Bugzilla – Attachment 189692 Details for
Bug 36434
Use a keyword that will be secretly included in all OPAC bibliographic and authority searches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36434 [alternate WIP]: Specify a search index and value to limit results on the opac
Bug-36434-alternate-WIP-Specify-a-search-index-and.patch (text/plain), 7.36 KB, created by
Nick Clemens (kidclamp)
on 2025-11-19 01:44:14 UTC
(
hide
)
Description:
Bug 36434 [alternate WIP]: Specify a search index and value to limit results on the opac
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2025-11-19 01:44:14 UTC
Size:
7.36 KB
patch
obsolete
>From be42ff686acfbc55d27338a0ae3718d797abcde1 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 27 Mar 2024 01:05:00 +0000 >Subject: [PATCH] Bug 36434 [alternate WIP]: Specify a search index and value > to limit results on the opac > >Similar to suppression, this patch adds two new system preferences >OPACAlwaysSearchIndex and OPACAlwaysSearchValue which will be used to add a limit >to the search results when OPACSuppression is enabled > >This is only done for Elasticsearch and only for biblios currently, not authorities, but could be extended >This also shows up in your search history, as suppression currently does (maybe a syspref to hide it?) > >The test plan below is simple, but ideally you would add a new index and use that, and probably not make it generally searchable > >Handling this in the query builder routines makes it testable, which I think is nice > >To test: > 1 - Have a Koha using Elasticsearch > 2 - Install database updates and restart services. > 3 - Do a standard OPAC search using the main search bar for 'a' and note the resuls > 4 - Do an advanced OPAC search, specify keyword: 'a' and homebranch: 'CPL'. Notice the number of results. > 5 - Go to the Koha Administration -> System preferences and search for 'OPACAlways'. > 6 - Note the two new preferences and add 'homebranch' for ..Index and 'CPL' for ..Value and Save. > 7 - Repeat steps 2 and 3. > 8 - Confirm results are returned, the basic search should now return results of the advanced search > 9 - The advanced search should not change. >10 - Remove the test keyword from OPACAlwaysSearchKeyword and Save. >--- > .../Elasticsearch/QueryBuilder.pm | 10 ++++++++- > ...4_-_add_OPACAlwaysSearchKeyword_syspref.pl | 22 +++++++++++++++++++ > .../modules/admin/preferences/searching.pref | 6 +++++ > opac/opac-authorities-home.pl | 7 +++--- > 4 files changed, 41 insertions(+), 4 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 8ee830c6498..7eb5963cac8 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -295,7 +295,15 @@ sub build_query_compat { > ? $self->_build_field_match_boost_query( { operands => $operands, indexes => \@index_params } ) > : []; > $limits = $self->_fix_limit_special_cases($orig_limits); >- if ( $params->{suppress} ) { push @$limits, "suppress:false"; } >+ if ( $params->{suppress} ) { >+ push @$limits, "suppress:false"; >+ if ( C4::Context->preference('OPACAlwaysSearchIndex') && C4::Context->preference('OPACAlwaysSearchValue') ) >+ { >+ push @$limits, >+ C4::Context->preference('OPACAlwaysSearchIndex') . ":" >+ . C4::Context->preference('OPACAlwaysSearchValue'); >+ } >+ } > > # Merge the indexes in with the search terms and the operands so that > # each search thing is a handy unit. >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..9baf2113170 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_36434_-_add_OPACAlwaysSearchKeyword_syspref.pl >@@ -0,0 +1,22 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "36434", >+ description => >+ "Specify an index/value 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 >+ ('OPACAlwaysSearchIndex', '', NULL, 'Force OPAC bibliographic and authority searches to additionally search the provided index for the value from OPACAlwaysSearchValue', 'Free'), >+ ('OPACAlwaysSearchValue', '', NULL, 'Force OPAC bibliographic and authority searches to additionally search the povided value in the index specified in OPACAlwaysSearchIndex', 'Free') >+ } >+ ); >+ >+ say $out "Added system preferences 'OPACAlwaysSearchIndex' / 'OPACAlwaysSearchValue'"; >+ }, >+}; >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 6c7e8d0e78a..94e02716e64 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 >@@ -131,6 +131,12 @@ Searching: > - "<pre>ccode: [REF,ARC]</pre><br/> - would mark all REF and ARC collections (Reference and Archives) items as unavailable in Z3950 results.<br/><br/>" > - "You can define multiple keys and values, items meeting ANY of the criteria will be marked unavailable:<br/><br/>" > - "<pre>itype: [REF]<br/>holdingbranch: [REPAIR]</pre><br/> - would mark all reference items AND items at the REPAIR branch as unavailable." >+ - >+ - Force OPAC bibliographic and authority searches to additionally search the index >+ - pref: OPACAlwaysSearchIndex >+ - "for the value" >+ - pref: OPACAlwaysSearchValue >+ - "to limit search results. Leave empty to disable this feature, both fields must be specified." > Search form: > - > - pref: LoadSearchHistoryToTheFirstLoggedUser >diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl >index 7206d3e351f..418f21d04fb 100755 >--- a/opac/opac-authorities-home.pl >+++ b/opac/opac-authorities-home.pl >@@ -56,6 +56,7 @@ if ( $op eq "do_search" ) { > my $orderby = $query->param('orderby'); > my @value = $query->multi_param('value'); > $value[0] ||= q||; >+ my $value_history = $value[0]; > > # validation of "Where" > my @valid_marc_list = qw( all match mainentry ); >@@ -81,7 +82,7 @@ if ( $op eq "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]" >@@ -159,7 +160,7 @@ if ( $op eq "do_search" ) { > 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", >@@ -172,7 +173,7 @@ if ( $op eq "do_search" ) { > { > userid => $loggedinuser, > sessionid => $query->cookie("CGISESSID"), >- query_desc => $value[0], >+ query_desc => $value_history, > query_cgi => $query_cgi_history, > total => $total, > type => "authority", >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36434
:
163969
| 189692