From 926f8097026cf4e1b480f72053935512be4efc04 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 27 Mar 2024 01:05:00 +0000 Subject: [PATCH] Bug 36434: Use a keyword that will be secretly included in all OPAC bibliographic and authority searches When a keyword is provided to the new OPACAlwaysSearchKeyword system preference, Koha will secretly add this to all OPAC searches (both bibliographic and authority) to help limit results. Note: This will have unexpected results if authority searches are done with 'starts with' or 'is exactly'. It is only designed to work with 'contains'. To test: 1. Install database updates and restart services. 2. Do a standard OPAC search using the main search bar for 'this that'. Notice the number of results. 3. Do an advanced OPAC search, specify keyword: 'this' and keyword: 'that'. Notice the number of results. 4. In the staff interface, do a biblio search for 'this that'. Edit the first two records, and put your test keyword somewhere in the MARC, perhaps a note field 5XX. 5. Go to the Koha Administration -> System preferences and search for OPACAlwaysSearchKeyword. Add your test keyword to the syspref and Save. 6. Repeat steps 2 and 3. Confirm results are returned, and there should only be your two records which you added the test keyword to. 7. Remove the test keyword from OPACAlwaysSearchKeyword and Save. 8. Do an OPAC authority search for 'series'. Notice the number of results. 9. In the staff interface, do an authority search for 'series'. Edit the first two records, and put your test keyword somewhere in the MARC, perhaps in the 040$f. 10. Repeat step 5. 11. Repeat steps 8 and 9. Confirm results are returned, and there should only be your two records which you added the test keyword to. 12. Click on 'Welcome, your name' in the top right of the OPAC and go to your search history. Confirm the test keyword added to OPACAlwaysSearchKeyword does NOT show in your history, for both catalog and authority searches. 13. Confirm all results are returned as normal when OPACAlwaysSearchKeyword is empty. Sponsored-by: Auckland University of Technology --- ...6434_-_add_OPACAlwaysSearchKeyword_syspref.pl | 16 ++++++++++++++++ .../en/modules/admin/preferences/searching.pref | 5 +++++ opac/opac-authorities-home.pl | 13 ++++++++++--- opac/opac-search.pl | 7 +++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl diff --git a/installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl b/installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl new file mode 100755 index 00000000000..1f40f1faa5b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "36434", + description => "Use a keyword that will be secretly included in all OPAC bibliographic and authority searches", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('OPACAlwaysSearchKeyword', '', NULL, 'Force OPAC bibliographic and authority searches to additionally search the provided keyword, to quietly limit search results', 'Free') } + ); + + say $out "Added system preference 'OPACAlwaysSearchKeyword'"; + }, +}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 86b9f54ae15..4b76bdd22e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -94,6 +94,11 @@ Searching: 1: Enable 0: Disable - "the option for staff with permission to create/edit custom saved search filters." + - + - Force OPAC bibliographic and authority searches to additionally search + - pref: OPACAlwaysSearchKeyword + - ", to quietly limit search results. Leave empty to disable this feature." + - "IMPORTANT: If enabled, this may have unexpected results when doing a 'starts with' or 'is exactly' search. It is designed to work with a 'contains' search only." Search form: - - pref: LoadSearchHistoryToTheFirstLoggedUser diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index 8b57bac2999..215e6c39878 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -56,6 +56,13 @@ if ( $op eq "cud-do_search" ) { my $orderby = $query->param('orderby'); my @value = $query->multi_param('value'); $value[0] ||= q||; + my $value_history = $value[0]; + + if ( C4::Context->preference('OPACAlwaysSearchKeyword') ) { + my $always_search_kw = C4::Context->preference('OPACAlwaysSearchKeyword'); + $always_search_kw =~ s/^\s+|\s+$//g; + $value[0] = $value[0] . " " . $always_search_kw; + } # validation of "Where" my @valid_marc_list = qw( all match mainentry ); @@ -82,7 +89,7 @@ if ( $op eq "cud-do_search" ) { $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate'); # multi page display gestion - my $value_url = uri_escape_utf8($value[0]); + my $value_url = uri_escape_utf8($value_history); my $base_url = "opac-authorities-home.pl?" ."marclist=$marclist[0]" ."&and_or=$and_or[0]" @@ -158,7 +165,7 @@ if ( $op eq "cud-do_search" ) { unless ( $loggedinuser ) { my $new_search = C4::Search::History::add_to_session({ cgi => $query, - query_desc => $value[0], + query_desc => $value_history, query_cgi => $query_cgi_history, total => $total, type => "authority", @@ -168,7 +175,7 @@ if ( $op eq "cud-do_search" ) { C4::Search::History::add({ userid => $loggedinuser, sessionid => $query->cookie("CGISESSID"), - query_desc => $value[0], + query_desc => $value_history, query_cgi => $query_cgi_history, total => $total, type => "authority", diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 16b69332ff3..5a7a692c99a 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -414,6 +414,11 @@ if ($indexes[0] && !$indexes[1]) { # an operand can be a single term, a phrase, or a complete ccl query my @operands = $cgi->multi_param('q'); @operands = map { uri_unescape($_) } @operands; +if ( C4::Context->preference('OPACAlwaysSearchKeyword') ) { + my $always_search_kw = C4::Context->preference('OPACAlwaysSearchKeyword'); + $always_search_kw =~ s/^\s+|\s+$//g; + push @operands, $always_search_kw; +} $template->{VARS}->{querystring} = join(' ', @operands); @@ -715,6 +720,8 @@ for (my $i=0;$i<@servers;$i++) { my $query_cgi_history = $cgi->url(-query=>1); $query_cgi_history =~ s/^$path_info\?//; $query_cgi_history =~ s/;/&/g; + my $always_search_kw = C4::Context->preference('OPACAlwaysSearchKeyword'); + $query_desc =~ s/ AND kw,wrdl: $always_search_kw//; my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc; if ( $borrowernumber and $cgi->cookie("CGISESSID") ) { -- 2.30.2