Bug 27546: Add 'Search within results' search box
authorNick Clemens <nick@bywatersolutions.com>
Thu, 21 Jan 2021 14:23:35 +0000 (14:23 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 20 Jul 2022 12:23:25 +0000 (09:23 -0300)
This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
catalogue/search.pl
koha-tmpl/intranet-tmpl/prog/en/includes/catalogue-search-box.inc
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt

index b244beb..a7eac00 100755 (executable)
@@ -366,7 +366,7 @@ if ($indexes[0] && (!$indexes[1] || $params->{'scan'})) {
     my $idx = "ms_".$indexes[0];
     $idx =~ s/\,/comma/g;  # template toolkit doesn't like variables with a , in it
     $idx =~ s/-/dash/g;  # template toolkit doesn't like variables with a dash in it
-    $template->param($idx => 1);
+    $template->param(header_pulldown => $idx);
 }
 
 # an operand can be a single term, a phrase, or a complete ccl query
index 134bf93..0bb0e63 100644 (file)
@@ -3,7 +3,7 @@
         <form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
             <label class="tip" for="search-form">Enter search keywords:</label>
                 [% IF ( Koha.Preference('IntranetCatalogSearchPulldown') ) %]
-                    [% INCLUDE 'search_indexes.inc' %]
+                    [% INCLUDE 'search_indexes.inc' $header_pulldown = 1 %]
                 [% END %]
             <input type="text" name="q" id="search-form" size="40" value="[% ms_value | html %]" title="Enter the terms you wish to search for." class="query form-text head-searchbox" />
             <input type="submit" value="Submit"  class="submit" />
index 8d952c8..ff13b58 100644 (file)
                         [% total | html %] result(s) found [% IF ( query_desc ) %]for <span class="results_query_desc">'[% query_desc | html %]'</span>[% END %][% IF limit_desc  %]&nbsp;with limit(s): <span class="results_limit_desc">'[% limit_desc | html %]'</span>[% END %][% IF ( LibraryName ) %] in [% LibraryName | html %] Catalog[% END %].
                     </h3>
                     <a href="/cgi-bin/koha/catalogue/search.pl?advsearch=1&edit_search=1&[% query_cgi | $raw %]&[% limit_cgi | $raw %]&sort_by=[% sort_by | $raw %]">Edit this search</a>
+                                                                                                                                      <div id="search_within_results">
+                        <form id="refine_search">
+                            <label for="limit">Search within results</label>
+                            [% IF ( Koha.Preference('IntranetCatalogSearchPulldown') ) %]
+                                [% INCLUDE 'search_indexes.inc' ms_kw = 1 %]
+                            [% END %]
+                            <input name="limit" id="refiner" type="text"  title="Search results">
+                            <input type="submit" id="refine" value="Search">
+                        </form>
+                    </div>
 
                     <div class="searchheader" id="searchheader">
                         <div id="selection_ops">
             first_biblionumber: "[% SEARCH_RESULTS.first.biblionumber | html %]",
             last_biblionumber: "[% SEARCH_RESULTS.last.biblionumber | html %]",
         }
+
+        $("#refine_search").on('submit',function(e){
+            e.preventDefault();
+            var index = $("#refine_search #idx").val() || "";
+            if( index){index += ":";}
+            window.location.href = "/cgi-bin/koha/catalogue/search.pl?[% query_cgi | $raw %]&[% limit_cgi | $raw %]&[% sort_cgi | $raw %]&limit="+index+$("#refiner").val();
+        });
     </script>
     [% Asset.js("js/pages/results.js") | $raw %]
 [% END %]