Bug 21032: Fix using facet for searches made on specific index
authorAlex Arnaud <alex.arnaud@biblibre.com>
Tue, 3 Jul 2018 13:57:00 +0000 (13:57 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Jul 2018 16:11:56 +0000 (13:11 -0300)
Test plan:

  - Try a simple search (OPAC or staff) like "title:foo",
  - click on a facet: badaboum!
  - apply this patch,
  - retry

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t

index 4e6a6e9..40c88b9 100644 (file)
@@ -238,7 +238,7 @@ sub build_query_compat {
     #die Dumper($query);
     # We roughly emulate the CGI parameters of the zebra query builder
     my $query_cgi;
-    $query_cgi = 'idx=kw&q=' . uri_escape_utf8( $operands->[0] ) if @$operands;
+    $query_cgi = 'q=' . uri_escape_utf8( $operands->[0] ) if @$operands;
     my $simple_query;
     $simple_query = $operands->[0] if @$operands == 1;
     my $query_desc   = $simple_query;
index 7466f07..0925322 100644 (file)
@@ -92,7 +92,7 @@ subtest 'json2marc' => sub {
 };
 
 subtest 'build_query tests' => sub {
-    plan tests => 23;
+    plan tests => 24;
 
     t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
     my $query = $builder->build_query();
@@ -232,12 +232,14 @@ subtest 'build_query tests' => sub {
         "query of specific field is added AND suppress:0"
     );
 
-    ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
+    my ($simple_query, $query_cgi);
+    ( undef, $query, $simple_query, $query_cgi ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
     is(
         $query->{query}{query_string}{query},
         '(title:"donald duck")',
         "query of specific field is not added AND suppress:0"
     );
+    is($query_cgi, 'q=title%3A%22donald%20duck%22', 'query cgi');
 };
 
 subtest "_convert_sort_fields" => sub {