src/snac/server/elastic/ElasticSearchUtil.php
/**
     * Search SNAC Resources Index
     *
     * Searches the resources 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)
     * @param array $filters optional Array of term => value pairs to filter by (default null)
     * @return string[] Results from Elastic Search: total, results list, pagination (num pages), page (current page)
     */
Search SNAC Resources Index
Searches the resources index for the query.  Allows for pagination by the start and count parameters.


Search SNAC Resources Index Searches the resources index for the query . Allows for pagination by the start and count parameters .
public function searchResourceIndex($query, $start=0, $count=10, $filters=null) {
        $this->logger->addDebug("Searching for a Resource");
        if (\snac\Config::$USE_ELASTIC_SEARCH) {
            $params = [
                'index' => \snac\Config::$ELASTIC_SEARCH_RESOURCE_INDEX,
                'body'  => [
                    'query' => [
                        'bool' => [
                            'must' => [
                                        'multi_match' => [
                                            'type' => 'phrase',
                                            'query' => $query,
                                            'fields' => ['title', 'abstract', 'url'],
                                        ]
                            ]
                        ]
                    ],
                ],
                'from' => $start,
                'size' => $count
            ];
            if (isset($filters)){
                $queryFilter = [];
                foreach ($filters as $field => $value) {
                    $queryFilter['term'][$field] = $value;
                }
                $params['body']['query']['bool']['filter'][] = $queryFilter;
            }
            $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 resource search response to the user", $response);
            return $response;
        }
        return array (
                    "notice" => "Not Using ElasticSearch"
        );
    }
public function searchResourceIndex ( $ query , $ start = 0 , $ count = 10 , $ filters = null ) { $ this -> logger -> addDebug ( " Searching for a Resource " ) ; if ( \ snac \ Config :: $ USE_ELASTIC_SEARCH ) { $ params = [ 'index' => \ snac \ Config :: $ ELASTIC_SEARCH_RESOURCE_INDEX , 'body' => [ 'query' => [ 'bool' => [ 'must' => [ 'multi_match' => [ 'type' => 'phrase' , 'query' => $ query , 'fields' => [ 'title' , 'abstract' , 'url' ] , ] ] ] ] , ] , 'from' => $ start , 'size' => $ count ] ; if ( isset ( $ filters ) ) { $ queryFilter = [ ] ; foreach ( $ filters as $ field => $ value ) { $ queryFilter [ 'term' ] [ $ field ] = $ value ; } $ params [ 'body' ] [ 'query' ] [ 'bool' ] [ 'filter' ] [ ] = $ queryFilter ; } $ 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 resource search response to the user " , $ response ) ; return $ response ; } return array ( " notice " => " Not Using ElasticSearch " ) ; }
Search SNAC Resources Index
 Searches the resources index for the query.
Search SNAC Resources Index Searches the resources index for the query .
// build an ES filter and append to $params