From c6a0049d5432fb1351bca8f0e9fd1cca1b04b6b5 Mon Sep 17 00:00:00 2001 From: Magnus Enger Date: Thu, 6 May 2021 12:46:40 +0200 Subject: [PATCH] Bug 25885 - Show list of hits for one search result Default behaviour in Koha, for a bibliographic search that returns one hit is to skip the result list and go straight to the detail view of that one hit. This patch makes this behaviour configurable. To test: - Make sure you can do a search that returns exactly one hit - Apply this patch - Do the search and verify the default behaviour of skipping the result list and going straight to detail view is in place - Toggle the OPACShowResultListOfOne syspref and make sure the behaviour corresponds to the setting. Signed-off-by: Lucas Gass --- .../atomicupdate/bug25885-show-result-list-for-one-hit.perl | 9 +++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/searching.pref | 6 ++++++ opac/opac-search.pl | 6 ++++-- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug25885-show-result-list-for-one-hit.perl diff --git a/installer/data/mysql/atomicupdate/bug25885-show-result-list-for-one-hit.perl b/installer/data/mysql/atomicupdate/bug25885-show-result-list-for-one-hit.perl new file mode 100644 index 0000000000..5d113d0c22 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug25885-show-result-list-for-one-hit.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) + VALUES ('OPACShowResultListOfOne','0','Show the result list even if there is only one hit.',NULL,'YesNo') + }); + + NewVersion( $DBversion, 25885, 'OPACShowResultListOfOne, show result list if there is only one hit' ); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 2ae86ad3d2..ff4cf1f901 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -493,6 +493,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpenURLImageLocation', '', NULL, 'Location of image for OpenURL links', 'Free'), ('OPACFineNoRenewalsIncludeCredits','1',NULL,'If enabled the value specified in OPACFineNoRenewals should include any unapplied account credits in the calculation','YesNo'), ('OPACShowOpenURL', '0', NULL, 'Enable display of OpenURL links in OPAC search results and detail page', 'YesNo'), +('OPACShowResultListOfOne', '0', NULL, 'Show the result list even if there is only one hit.', 'YesNo'), ('OPACOpenURLItemTypes', '', NULL, 'Show the OpenURL link only for these item types', 'Free'), ('OrderPdfFormat','pdfformat::layout3pages','Controls what script is used for printing (basketgroups)','','free'), ('OrderPriceRounding','','|nearest_cent','Local preference for rounding orders before calculations to ensure correct calculations','Choice'), 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 25b3878307..c797a9e646 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 @@ -273,6 +273,12 @@ Searching: 1: "Display" 0: "Don't display" - ' Koha record level itemtype info on detail and result pages in the OPAC and staff interface. This info also displays if the item-level_itypes system preference is set to bibliographic record.' + - + - pref: OPACShowResultListOfOne + choices: + 1: "Show" + 0: "Don't show" + - ' the result list if there is only one hit. This is especially useful if you use a service like OverDrive and want to display the link on the result list, without automatically redirecting to detail view for a single hit.' Did you mean/spell checking: - - "Swedish service for spellchecking.
" diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 878d97826f..7f8a45327d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -789,9 +789,11 @@ for (my $i=0;$i<@servers;$i++) { $template->param( EnableOpacSearchHistory => 1 ); } - ## If there's just one result, redirect to the detail page + # If there's just one result, redirect to the detail page unless this + # funtionality has been turned off with the syspref OPACShowResultListOfOne if ($total == 1 && $format ne 'rss' - && $format ne 'opensearchdescription' && $format ne 'atom') { + && $format ne 'opensearchdescription' && $format ne 'atom' + && C4::Context->preference('OPACShowResultListOfOne') == 0 ) { my $biblionumber=$newresults[0]->{biblionumber}; if (C4::Context->preference('BiblioDefaultView') eq 'isbd') { print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber"); -- 2.11.0