<<

NAME

Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch

SYNOPSIS

    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];
    });

METHODS

search

    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:

offset

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

count

    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.

search_compat

    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.)

search_auth_compat

    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.

count_auth_use

    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.

simple_search_compat

    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:

$query

A thing to search for. It could be a simple string, or something constructed with the appropriate QueryBuilder module.

$offset

How many results to skip from the start of the results.

$max_results

The max number of results to return. The default is 100 (because unlimited is a pretty terrible thing to do.)

Returns:

$error

if something went wrong, this'll contain some kind of error message.

$marcresults

an arrayref of MARC::Records (note that this is different from the C4::Search version which will return plain XML, but too bad.)

$total_hits

the total number of results that this search could have returned.

json2marc

    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.

_convert_facets

    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.

<<