src/snac/server/elastic/ElasticSearchUtil.php
/**
     * Advanced Search SNAC Main Index
     *
     * Searches the main names index for the query using number of related resources as a factor, while also using the
     * Elastic Search simple_query_string query that allows for wildcard, missing, and edit distance queries.
     * Allows for pagination by the start and count parameters.
     *
     * @param string $query The search query
     * @param string $entityType optional The entity type to search for, or null
     * @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 string[][] $parameters optional The list of facets and other parameters to use when performing this search
     * @param boolean $fullSearch optional Whether to search the full text (i.e. biogHist plus names).
     * @return string[] Results from Elastic Search: total, results list, pagination (num pages), page (current page)
     */
Advanced Search SNAC Main Index
Searches the main names index for the query using number of related resources as a factor, while also using the
Elastic Search simple_query_string query that allows for wildcard, missing, and edit distance queries.
Allows for pagination by the start and count parameters.


Advanced Search SNAC Main Index Searches the main names index for the query using number of related resources as a factor while also using the Elastic Search simple_query_string query that allows for wildcard missing and edit distance queries . Allows for pagination by the start and count parameters .
public function searchMainIndexAdvanced($query, $entityType=null, $start=0, $count=10, $parameters=null, $fullSearch=false) {
        $searchBody = [
            'query' => [
                'function_score' => [
                    'query' => [
                        'bool' => [
                            'must' => [
                               'simple_query_string' => [
                                   'fields' => ['nameEntry'],
                                   'query' => $query,
                                   'default_operator' => 'and'
                               ]
                           ],
                           "filter" => [
                           ]
                        ]
                    ],
                    'field_value_factor' => [
                        'field' => 'resources',
                        'modifier' => 'log1p',
                        'factor' => 1.5
                    ],
                    'boost_mode' => "multiply",
                    'max_boost' => 3
                ]
            ]
        ];
        if ($fullSearch !== false) {
            unset($searchBody["query"]["function_score"]["query"]["bool"]["must"]);
            $searchBody["query"]["function_score"]["query"]["bool"]["should"] = [
                [
                    'simple_query_string' => [
                        'fields' => ['nameEntry', 'biogHist'],
                        'query' => $query,
                        'default_operator' => 'and'
                    ]
                ]
            ];
            $searchBody["query"]["function_score"]["query"]["bool"]["minimum_should_match"] = 1;
        }
        if ($entityType !== null) {
            array_push($searchBody["query"]["function_score"]["query"]["bool"]["filter"], [
                'term' => [
                    'entityType' => $entityType
                ]
            ]);
        }
        if ($parameters !== null && is_array($parameters) && !empty($parameters)) {
            if ($query == "" ) {
                if (isset($searchBody["query"]["function_score"]["query"]["bool"]["must"]))
                    unset($searchBody["query"]["function_score"]["query"]["bool"]["must"]);
                if (isset($searchBody["query"]["function_score"]["query"]["bool"]["should"]))
                    unset($searchBody["query"]["function_score"]["query"]["bool"]["should"]);
                if (isset($searchBody["query"]["function_score"]["query"]["bool"]["minimum_should_match"]))
                    unset($searchBody["query"]["function_score"]["query"]["bool"]["minimum_should_match"]);
                $searchBody["sort"] = [
                    [ "nameEntry" => "asc" ],
                    "_score"
                ];
            }
            foreach ($parameters as $type=>$values) {
                foreach ($values as $value) {
                    array_push($searchBody["query"]["function_score"]["query"]["bool"]["filter"], [
                        'match' => [
                            $type => [
                                'query' => $value
                            ]
                        ]
                    ]);
                }
            }
        }
        return $this->elasticSearchQuery($searchBody, $start, $count);
    }
public function searchMainIndexAdvanced ( $ query , $ entityType = null , $ start = 0 , $ count = 10 , $ parameters = null , $ fullSearch = false ) { $ searchBody = [ 'query' => [ 'function_score' => [ 'query' => [ 'bool' => [ 'must' => [ 'simple_query_string' => [ 'fields' => [ 'nameEntry' ] , 'query' => $ query , 'default_operator' => 'and' ] ] , " filter " => [ ] ] ] , 'field_value_factor' => [ 'field' => 'resources' , 'modifier' => 'log1p' , 'factor' => 1.5 ] , 'boost_mode' => " multiply " , 'max_boost' => 3 ] ] ] ; if ( $ fullSearch !== false ) { unset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " must " ] ) ; $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " should " ] = [ [ 'simple_query_string' => [ 'fields' => [ 'nameEntry' , 'biogHist' ] , 'query' => $ query , 'default_operator' => 'and' ] ] ] ; $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " minimum_should_match " ] = 1 ; } if ( $ entityType !== null ) { array_push ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " filter " ] , [ 'term' => [ 'entityType' => $ entityType ] ] ) ; } if ( $ parameters !== null && is_array ( $ parameters ) && ! empty ( $ parameters ) ) { if ( $ query == " " ) { if ( isset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " must " ] ) ) unset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " must " ] ) ; if ( isset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " should " ] ) ) unset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " should " ] ) ; if ( isset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " minimum_should_match " ] ) ) unset ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " minimum_should_match " ] ) ; $ searchBody [ " sort " ] = [ [ " nameEntry " => " asc " ] , " _score " ] ; } foreach ( $ parameters as $ type => $ values ) { foreach ( $ values as $ value ) { array_push ( $ searchBody [ " query " ] [ " function_score " ] [ " query " ] [ " bool " ] [ " filter " ] , [ 'match' => [ $ type => [ 'query' => $ value ] ] ] ) ; } } } return $ this -> elasticSearchQuery ( $ searchBody , $ start , $ count ) ; }
Advanced Search SNAC Main Index
 Searches the main names index for the query using number of related resources as a factor, while also using the
 Elastic Search simple_query_string query that allows for wildcard, missing, and edit distance queries.
Advanced Search SNAC Main Index Searches the main names index for the query using number of related resources as a factor while also using the Elastic Search simple_query_string query that allows for wildcard missing and edit distance queries .
/* This query uses a full-word matching search */ // Allow an empty query that will just return whatever (as long as there are parameters