From 45834b214c6889f6748608768c60d10311d1ae64 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 11 Mar 2015 16:14:14 +1300 Subject: [PATCH] Bug 12478: fix the way counting is done Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/SearchEngine/Elasticsearch/Search.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index a745c5e4ec..aa8640f769 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -85,10 +85,9 @@ sub search { } $self->store( Catmandu::Store::ElasticSearch->new( - %$params, - trace_calls => 1, + %$params, trace_calls => 1, ) - ); + ) unless $self->store; my $results = $self->store->bag->search( %$query, %paging ); return $results; } @@ -107,11 +106,11 @@ sub count { my $params = $self->get_elasticsearch_params(); $self->store( - Catmandu::Store::ElasticSearch->new( %$params, trace_calls => 1, ) ); + Catmandu::Store::ElasticSearch->new( %$params, trace_calls => 1, ) ) + unless $self->store; - # TODO something like this should work, but doesn't seem to just yet. - # my $count = $self->store->bag->count($query); - my $count = $self->store->bag->search(%$query)->total; + my $searcher = $self->store->bag->searcher(query => $query); + my $count = $searcher->count(); return $count; } -- 2.39.5