<<

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,       undef,           $item_types,
        $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, $offset, $count, $skipmetadata, %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, %options );

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

%options

These options are unused by Elasticsearch

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.

extract_biblionumber

    my $biblionumber = $searcher->extract_biblionumber( $searchresult );

$searchresult comes from simple_search_compat.

Returns the biblionumber from the search result record.

decode_record_from_result my $marc_record = $self->decode_record_from_result(@result);

Extracts marc data from Elasticsearch result and decodes to MARC::Record object

max_result_window

Returns the maximum number of results that can be fetched

This directly requests Elasticsearch for the setting index.max_result_window (or the default value for this setting in case it is not set)

_convert_facets

    my $koha_facets = _convert_facets($es_facets);

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.

_aggregation_scan

    my $result = $self->_aggregration_scan($query, 10, 0);

Perform an aggregation request for scan purposes.

<<