Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch
my $searcher =
Koha::SearchEngine::ElasticSearch::Search->new( { index => $index } );
my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new(
{ index => $index } );
my $query = $builder->build_query('perl');
my $results = $searcher->search($query);
print "There were " . $results->total . " results.\n";
$results->each(sub {
push @hits, @_[0];
});
my $results = $searcher->search($query, $page, $count, %options);
Run a search using the query. It'll return $count results, starting at page $page ($page counts from 1, anything less that, or undef becomes 1.) $count is also the number of entries on a page.
%options is a hash containing extra options:
If provided, this overrides the $page value, and specifies the record as an offset (i.e. the number of the record to start with), rather than a page.
Returns
my $count = $searcher->count($query);
This mimics a search request, but just gets the result count instead. That's faster than pulling all the data in, usually.
my ( $error, $results, $facets ) = $search->search_compat(
$query, $simple_query, \@sort_by, \@servers,
$results_per_page, $offset, $expanded_facet, $branches,
$query_type, $scan
)
A search interface somewhat compatible with C4::Search-getRecords>. Anything that is returned in the query created by build_query_compat will probably get ignored here, along with some other things (like @servers.)
my ( $results, $total ) =
$searcher->search_auth_compat( $query, $page, $count, %options );
This has a similar calling convention to search, however it returns its results in a form the same as C4::AuthoritiesMarc::SearchAuthorities.
my $count = $auth_searcher->count_auth_use($bib_searcher, $authid);
This runs a search to determine the number of records that reference the specified authid. $bib_searcher must be something compatible with elasticsearch, as the query is built in this function.
my ( $error, $marcresults, $total_hits ) =
$searcher->simple_search( $query, $offset, $max_results );
This is a simpler interface to the searching, intended to be similar enough to C4::Search::SimpleSearch.
Arguments:
$queryA thing to search for. It could be a simple string, or something constructed with the appropriate QueryBuilder module.
$offsetHow many results to skip from the start of the results.
$max_resultsThe max number of results to return. The default is 100 (because unlimited is a pretty terrible thing to do.)
Returns:
$errorif something went wrong, this'll contain some kind of error message.
$marcresultsan arrayref of MARC::Records (note that this is different from the C4::Search version which will return plain XML, but too bad.)
$total_hitsthe total number of results that this search could have returned.
my $marc = $self->json2marc($marc_json);
Converts the form of marc (based on its JSON, but as a Perl structure) that Catmandu stores into a MARC::Record object.
my $koha_facets = _convert_facets($es_facets, $expanded_facet);
Converts elasticsearch facets types to the form that Koha expects. It expects the ES facet name to match the Koha type, for example itype, au, su-to, etc.
$expanded_facet is the facet that we want to show FacetMaxCount entries for, rather than just 5 like normal.