Bug 12478: fix the way counting is done
authorRobin Sheat <robin@catalyst.net.nz>
Wed, 11 Mar 2015 03:14:14 +0000 (16:14 +1300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 26 Apr 2016 12:55:36 +0000 (09:55 -0300)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Koha/SearchEngine/Elasticsearch/Search.pm

index a745c5e..aa8640f 100644 (file)
@@ -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;
 }