src/snac/server/elastic/ElasticSearchUtil.php
/**
     * Search SNAC Main Index
     *
     * Searches the main names index for the query.  Allows for pagination by the start and count parameters.
     *
     * @param string $query The search query
     * @param integer $start optional The result index to start from (default 0)
     * @param integer $count optional The number of results to return from the start (default 10)
     * @return string[] Results from Elastic Search: total, results list, pagination (num pages), page (current page)
     */
Search SNAC Main Index
Searches the main names index for the query.  Allows for pagination by the start and count parameters.

@param string $query The search query
@param integer $start optional The result index to start from (default 0)
@param integer $count optional The number of results to return from the start (default 10)
@return string[] Results from Elastic Search: total, results list, pagination (num pages), page (current page)
Search SNAC Main Index Searches the main names index for the query . Allows for pagination by the start and count parameters . @param string $query The search query @param integer $start optional The result index to start from ( default 0 ) @param integer $count optional The number of results to return from the start ( default 10 ) @return string [] Results from Elastic Search : total results list pagination ( num pages ) page ( current page )
public function searchMainIndex($query, $start=0, $count=10) {
        $this->logger->addDebug("Searching for a Constellation");
        if (\snac\Config::$USE_ELASTIC_SEARCH) {
            $params = [
                'index' => \snac\Config::$ELASTIC_SEARCH_BASE_INDEX,
                'body' => [
                    'query' => [
                        'filtered' => [
                            'query' => [
                                'match_phrase_prefix' => [
                                    'nameEntry' => [
                                        'query' => $query,
                                        'slop' => 20
                                    ]
                                ]
                            ],
                            'filter' => [
                                'bool' => [
                                    'must' => [
                                        'term' => [
                                            'subject' => 'women sculptors'
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ],
                    'from' => $start,
                    'size' => $count
                ]
            ];
            $this->logger->addDebug("Defined parameters for search", $params);
            $results = $this->connector->search($params);
            $this->logger->addDebug("Completed Elastic Search", $results);
            $return = array ();
            foreach ($results["hits"]["hits"] as $i => $val) {
                array_push($return, $val["_source"]);
            }
            $response = array();
            $response["total"] = $results["hits"]["total"]["value"];    
            $response["results"] = $return;
            if ($response["total"] == 0 || $count == 0) {
                $response["pagination"] = 0;
                $response["page"] = 0;
            } else {
                $response["pagination"] = ceil($response["total"] / $count);
                $response["page"] = floor($start / $count);
            }
            $this->logger->addDebug("Created search response to the user", $response);
            return $response;
        }
        return array (
                    "notice" => "Not Using ElasticSearch"
        );
    }
public function searchMainIndex ( $ query , $ start = 0 , $ count = 10 ) { $ this -> logger -> addDebug ( " Searching for a Constellation " ) ; if ( \ snac \ Config :: $ USE_ELASTIC_SEARCH ) { $ params = [ 'index' => \ snac \ Config :: $ ELASTIC_SEARCH_BASE_INDEX , 'body' => [ 'query' => [ 'filtered' => [ 'query' => [ 'match_phrase_prefix' => [ 'nameEntry' => [ 'query' => $ query , 'slop' => 20 ] ] ] , 'filter' => [ 'bool' => [ 'must' => [ 'term' => [ 'subject' => 'women sculptors' ] ] ] ] ] ] , 'from' => $ start , 'size' => $ count ] ] ; $ this -> logger -> addDebug ( " Defined parameters for search " , $ params ) ; $ results = $ this -> connector -> search ( $ params ) ; $ this -> logger -> addDebug ( " Completed Elastic Search " , $ results ) ; $ return = array ( ) ; foreach ( $ results [ " hits " ] [ " hits " ] as $ i => $ val ) { array_push ( $ return , $ val [ " _source " ] ) ; } $ response = array ( ) ; $ response [ " total " ] = $ results [ " hits " ] [ " total " ] [ " value " ] ; $ response [ " results " ] = $ return ; if ( $ response [ " total " ] == 0 || $ count == 0 ) { $ response [ " pagination " ] = 0 ; $ response [ " page " ] = 0 ; } else { $ response [ " pagination " ] = ceil ( $ response [ " total " ] / $ count ) ; $ response [ " page " ] = floor ( $ start / $ count ) ; } $ this -> logger -> addDebug ( " Created search response to the user " , $ response ) ; return $ response ; } return array ( " notice " => " Not Using ElasticSearch " ) ; }
Search SNAC Main Index
 Searches the main names index for the query.
Search SNAC Main Index Searches the main names index for the query .
/* This query uses a keyword search
                       'query' => [
                        'query_string' => [
                            'fields' => [
                                "nameEntry"
                            ],
                            'query' => '*' . $input["term"] . '*'
                        ]
                    ],
                    'from' => $start,
                    'size' => $count*/ /* This query uses a full-phrase matching search
                    'query' => [
                        'match_phrase_prefix' => [
                            'nameEntry' => [
                                'query' => $query,
                                'slop' => 20
                            ]
                        ]
                    ],*/ // ES 7 syntax adds ["value"]