Bug 28610: Elasticsearch 7 - hits.total is now an object
In Elasticsearch 7 hits.total is now an object which is not always an exact value. You can always get an exact total by adding a track_total_hits parameter set to true when using the Elasticsearch search method To test: 1) Run prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t 2) If you observe an error about types, apply patch for bug 25669 3) Run prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t 4) Observe that tests with count fail 5) Apply patch 6) Observe that tests with count pass 7) Sign off Sponsored-by: Lund University Library Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
ae426e4486
commit
301ed1567b
2 changed files with 10 additions and 1 deletions
|
@ -51,6 +51,7 @@ use Koha::Exceptions::Elasticsearch;
|
|||
use MARC::Record;
|
||||
use MARC::File::XML;
|
||||
use MIME::Base64 qw( decode_base64 );
|
||||
use JSON;
|
||||
|
||||
Koha::SearchEngine::Elasticsearch::Search->mk_accessors(qw( store ));
|
||||
|
||||
|
@ -93,12 +94,16 @@ sub search {
|
|||
my $results = eval {
|
||||
$elasticsearch->search(
|
||||
index => $self->index_name,
|
||||
track_total_hits => JSON::true,
|
||||
body => $query
|
||||
);
|
||||
};
|
||||
if ($@) {
|
||||
die $self->process_error($@);
|
||||
}
|
||||
if (ref $results->{hits}->{total} eq 'HASH') {
|
||||
$results->{hits}->{total} = $results->{hits}->{total}->{value};
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
@ -119,9 +124,13 @@ sub count {
|
|||
# and just return number of hits
|
||||
my $result = $elasticsearch->search(
|
||||
index => $self->index_name,
|
||||
track_total_hits => JSON::true,
|
||||
body => $query
|
||||
);
|
||||
|
||||
if (ref $result->{hits}->{total} eq 'HASH') {
|
||||
return $result->{hits}->{total}->{value};
|
||||
}
|
||||
return $result->{hits}->{total};
|
||||
}
|
||||
|
||||
|
|
2
cpanfile
2
cpanfile
|
@ -91,7 +91,7 @@ requires 'Plack::Middleware::LogWarn', '0.001002';
|
|||
requires 'Plack::Middleware::ReverseProxy', '0.14';
|
||||
requires 'Readonly', '2.00';
|
||||
requires 'Schedule::At', '1.06';
|
||||
requires 'Search::Elasticsearch', '5.01';
|
||||
requires 'Search::Elasticsearch', '6.00';
|
||||
requires 'Sereal::Decoder', '3.0';
|
||||
requires 'Sereal::Encoder', '3.0';
|
||||
requires 'Storable', '2.20';
|
||||
|
|
Loading…
Reference in a new issue