Bug 20602: Use weighted fields in OPAC simple search
authorAlex Arnaud <alex.arnaud@gmail.com>
Wed, 18 Apr 2018 14:19:34 +0000 (14:19 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 7 Nov 2018 23:12:19 +0000 (23:12 +0000)
Test plan (having Koha working with Elasticsearch):
  - apply this patch,
  - try searches with and without weight defined on search fields

https://bugs.koha-community.org/show_bug.cgi?id=20262
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
opac/opac-search.pl

index 11e389a..1d7aada 100644 (file)
@@ -10,6 +10,7 @@
 [% INCLUDE 'bodytag.inc' bodyid='advsearch' bodyclass='scrollto' %]
 [% INCLUDE 'masthead.inc' %]
 <form action="/cgi-bin/koha/opac-search.pl" method="get">
+    <input type="hidden" name="advsearch" value="1"/>
     <div class="main">
         <ul class="breadcrumb">
             <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
index b4010a9..a18d509 100755 (executable)
@@ -58,6 +58,7 @@ use Koha::Ratings;
 use Koha::Virtualshelves;
 use Koha::Library::Groups;
 use Koha::Patrons;
+use Koha::SearchFields;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
@@ -548,18 +549,19 @@ if (C4::Context->preference('OpacSuppression')) {
     }
 }
 
+my $build_params = {
+    expanded_facet => $expanded_facet,
+    suppress => $suppress
+};
+
+unless ( $cgi->param('advsearch') ) {
+    $build_params->{weighted_fields} = 1;
+}
+
 ## I. BUILD THE QUERY
 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type)
-  = $builder->build_query_compat(
-    \@operators,
-    \@operands,
-    \@indexes,
-    \@limits,
-    \@sort_by,
-    0,
-    $lang,
-    { expanded_facet => $expanded_facet, suppress => $suppress }
-    );
+  = $builder->build_query_compat( \@operators, \@operands,
+    \@indexes, \@limits, \@sort_by, 0, $lang, $build_params);
 
 sub _input_cgi_parse {
     my @elements;