use Koha::ItemTypes;
use Koha::AuthorisedValues;
use Koha::SearchEngine::QueryBuilder;
+use Koha::SearchEngine::Search;
use MARC::Record;
use Catmandu::Store::ElasticSearch;
$servers, $results_per_page, $offset, $expanded_facet,
$branches, $query_type, $scan
) = @_;
-
my %options;
+ if ( !defined $offset or $offset < 0 ) {
+ $offset = 0;
+ }
$options{offset} = $offset;
$options{expanded_facet} = $expanded_facet;
my $results = $self->search($query, undef, $results_per_page, %options);
# I wonder if these should be real values defined in the mapping
# rather than hard-coded conversions.
- # Our results often come through as nested arrays, to fix this
- # requires changes in catmandu.
- my $authid = $record->{ 'Local-number' }[0][0];
+ # Handle legacy nested arrays indexed with splitting enabled.
+ my $authid = $record->{ 'Local-number' }[0];
+ $authid = @$authid[0] if (ref $authid eq 'ARRAY');
$result{authid} = $authid;
# TODO put all this info into the record at index time so we
# with the record. It's not documented why this is the case, so
# it's not reproduced here yet.
my $authtype = $rs->single;
- my $auth_tag_to_report = $authtype->auth_tag_to_report;
+ my $auth_tag_to_report = $authtype ? $authtype->auth_tag_to_report : "";
my $marc = $self->json2marc($marc_json);
my $mainentry = $marc->field($auth_tag_to_report);
my $reported_tag;
}
}
# Turn the resultset into a hash
- my %authtype_cols;
- foreach my $col ($authtype->result_source->columns) {
- $authtype_cols{$col} = $authtype->get_column($col);
- }
- $result{authtype} = $authtype->authtypetext;
+ $result{authtype} = $authtype ? $authtype->authtypetext : $authtypecode;
$result{reported_tag} = $reported_tag;
# Reimplementing BuildSummary is out of scope because it'll be hard
my $query = {
query => {
- filtered => {
- query => { match_all => {} },
+ bool => {
+# query => { match_all => {} },
filter => { term => { an => $authid } }
}
}
=head2 simple_search_compat
my ( $error, $marcresults, $total_hits ) =
- $searcher->simple_search( $query, $offset, $max_results );
+ $searcher->simple_search( $query, $offset, $max_results, %options );
This is a simpler interface to the searching, intended to be similar enough to
L<C4::Search::SimpleSearch>.
The max number of results to return. The default is 100 (because unlimited
is a pretty terrible thing to do.)
+=item C<%options>
+
+These options are unused by Elasticsearch
+
=back
Returns:
return ('No query entered', undef, undef) unless $query;
my %options;
- $options{offset} = $offset // 0;
+ $offset = 0 if not defined $offset or $offset < 0;
+ $options{offset} = $offset;
$max_results //= 100;
unless (ref $query) {
return (undef, \@records, $results->total);
}
+=head2 extract_biblionumber
+
+ my $biblionumber = $searcher->extract_biblionumber( $searchresult );
+
+$searchresult comes from simple_search_compat.
+
+Returns the biblionumber from the search result record.
+
+=cut
+
+sub extract_biblionumber {
+ my ( $self, $searchresultrecord ) = @_;
+ return Koha::SearchEngine::Search::extract_biblionumber( $searchresultrecord );
+}
+
=head2 json2marc
my $marc = $self->json2marc($marc_json);
return $marc;
}
+sub max_result_window {
+ my ($self) = @_;
+
+ $self->store(
+ Catmandu::Store::ElasticSearch->new(%{ $self->get_elasticsearch_params })
+ ) unless $self->store;
+
+ my $index_name = $self->store->index_name;
+ my $settings = $self->store->es->indices->get_settings(
+ index => $index_name,
+ params => { include_defaults => 1, flat_settings => 1 },
+ );
+
+ my $max_result_window = $settings->{$index_name}->{settings}->{'index.max_result_window'};
+ $max_result_window //= $settings->{$index_name}->{defaults}->{'index.max_result_window'};
+
+ return $max_result_window;
+}
+
=head2 _convert_facets
my $koha_facets = _convert_facets($es_facets, $expanded_facet);
'su-geo' => { order => 4, label => 'Places', },
se => { order => 5, label => 'Series', },
subject => { order => 6, label => 'Topics', },
+ ccode => { order => 7, label => 'CollectionCodes',},
+ holdingbranch => { order => 8, label => 'HoldingLibrary' },
+ homebranch => { order => 9, label => 'HomeLibrary' }
);
# We also have some special cases, e.g. itypes that need to show the
# value rather than the code.
my @itypes = Koha::ItemTypes->search;
+ my @libraries = Koha::Libraries->search;
+ my $library_names = { map { $_->branchcode => $_->branchname } @libraries };
my @locations = Koha::AuthorisedValues->search( { category => 'LOC' } );
my $opac = C4::Context->interface eq 'opac' ;
my %special = (
itype => { map { $_->itemtype => $_->description } @itypes },
location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
+ holdingbranch => $library_names,
+ homebranch => $library_names
);
my @facets;
$exp_facet //= '';