src/snac/server/elastic/ElasticSearchUtil.php
/**
     * Search SNAC Main Index with Resource Degree
     *
     * Searches the main names index for the query using number of related resources as a factor.  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)
     */
Search SNAC Main Index with Resource Degree
Searches the main names index for the query using number of related resources as a factor.  Allows for pagination by the start and count parameters.


Search SNAC Main Index with Resource Degree Searches the main names index for the query using number of related resources as a factor . Allows for pagination by the start and count parameters .
public function searchMainIndexWithDegree($query, $entityType=null, $start=0, $count=10, $parameters=null, $fullSearch=false) {
        $searchBody = [
            'query' => [
                'function_score' => [
                    'query' => [
                        'bool' => [
                            'must' => [
                                'match' => [
                                    'nameEntry' => [
                                        'query' => $query,
                                        '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"] = [
                [
                    'match' => [
                        'nameEntry' => [
                            'query' => $query,
                            'operator' => 'and'
                        ]
                    ]
                ],
                [
                    'match' => [
                        'biogHist' => [
                            'query' => $query,
                            '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 searchMainIndexWithDegree ( $ query , $ entityType = null , $ start = 0 , $ count = 10 , $ parameters = null , $ fullSearch = false ) { $ searchBody = [ 'query' => [ 'function_score' => [ 'query' => [ 'bool' => [ 'must' => [ 'match' => [ 'nameEntry' => [ 'query' => $ query , '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 " ] = [ [ 'match' => [ 'nameEntry' => [ 'query' => $ query , 'operator' => 'and' ] ] ] , [ 'match' => [ 'biogHist' => [ 'query' => $ query , '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 ) ; }
Search SNAC Main Index with Resource Degree
 Searches the main names index for the query using number of related resources as a factor.
Search SNAC Main Index with Resource Degree Searches the main names index for the query using number of related resources as a factor .
/* This query uses a full-word matching search */ // Allow an empty query that will just return whatever (as long as there are parameters // Filter on the given parameters // $type.".untokenized" => [