From 7b7b47ca6853cf5bfe438ff1c18b4987c2602f8a Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 14 Apr 2016 21:27:10 +0000 Subject: [PATCH] Bug 12478 Increasing test Coverage for Koha::SearchEngine::Elasticsearch::Search Before this patch it was 24.6%, after it is 64% 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 | 6 +++--- .../Koha_SearchEngine_Elasticsearch_Search.t | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 0950139fad..cfdad815ee 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -43,7 +43,7 @@ use C4::Context; use Koha::ItemTypes; use Koha::AuthorisedValues; use Koha::SearchEngine::QueryBuilder; - +use MARC::Record; use Catmandu::Store::ElasticSearch; use Data::Dumper; #TODO remove @@ -120,8 +120,8 @@ sub count { Catmandu::Store::ElasticSearch->new( %$params, trace_calls => 0, ) ) unless $self->store; - my $searcher = $self->store->bag->searcher(query => $query); - my $count = $searcher->count(); + my $search = $self->store->bag->search( %$query); + my $count = $search->total() || 0; return $count; } diff --git a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t index 6e6e2a4946..9361b4c3bd 100644 --- a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t +++ b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t @@ -17,7 +17,7 @@ use strict; use warnings; -use Test::More tests => 5; # last test to print +use Test::More tests => 10; # last test to print use Koha::SearchEngine::Elasticsearch::QueryBuilder; my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } ); @@ -36,3 +36,13 @@ is( $searcher->index, 'mydb', 'Testing basic accessor' ); ok( my $query = $builder->build_query('easy'), 'Build a search query'); ok( my $results = $searcher->search( $query) , 'Do a search ' ); + +ok( my $marc = $searcher->json2marc( $results->first ), 'Convert JSON to MARC'); + +is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results '); + +ok ($results = $searcher->search_compat( $query ), 'Test search_compat' ); + +ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' ); + +is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use'); -- 2.39.5