From 57569f6b8817b800c6bdf018541dfd67a1319a2f Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 8 Jan 2024 23:04:25 +0000 Subject: [PATCH] Bug 35728: Add ability to NOT redirect to result when search returns only one record This enhancement adds a new system preference RedirectToSoleResult. By default it is enabled, which matches current behaviour - to redirect to the detail page if it is the only search result. To test: 1) Apply the patch, install database updates, restart services. 2) Go to Koha Administration -> Global system preferences. The RedirectToSoleResult system preference is in the Searching tab. Confirm it is enabled (set to "Redirect") by default. 3) Conduct a catalogue search on the staff interface that you know will return a single result. Confirm you are redirected to the detail page. 4) Do the same search on the OPAC. Confirm you are redirected to the detail page. 5) Go back to the system preferences and disable the RedirectToSoleResult system preference by setting it to "Don't redirect" 6) Do the searches again on the staff interface and OPAC. Confirm you are NOT redirected to the detail page, and the search results page shows as expected. Sponsored-by: Education Services Australia SCIS Signed-off-by: David Nind Signed-off-by: Nick Clemens --- catalogue/search.pl | 17 +++++++++-------- opac/opac-search.pl | 16 ++++++++++------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/catalogue/search.pl b/catalogue/search.pl index 62283897179..c6ba6c52fe5 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -610,19 +610,20 @@ for (my $i=0;$i<@servers;$i++) { } ## If there's just one result, redirect to the detail page unless doing an index scan - if ($total == 1 && !$scan) { + if ( $total == 1 && !$scan && C4::Context->preference('RedirectToSoleResult') ) { my $biblionumber = $newresults[0]->{biblionumber}; - my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); - my $views = { C4::Search::enabled_staff_search_views }; - if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { + my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); + my $views = {C4::Search::enabled_staff_search_views}; + if ( $defaultview eq 'isbd' && $views->{can_view_ISBD} ) { print $cgi->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&found1=1"); - } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { + } elsif ( $defaultview eq 'marc' && $views->{can_view_MARC} ) { print $cgi->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&found1=1"); - } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) { - print $cgi->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&found1=1"); + } elsif ( $defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC} ) { + print $cgi->redirect( + "/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&found1=1"); } else { print $cgi->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&found1=1"); - } + } exit; } diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 16b69332ff3..e255e6fd10b 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -746,16 +746,20 @@ for (my $i=0;$i<@servers;$i++) { } ## If there's just one result, redirect to the detail page - if ($total == 1 && $format ne 'rss' - && $format ne 'opensearchdescription' && $format ne 'atom') { - my $biblionumber=$newresults[0]->{biblionumber}; - if (C4::Context->preference('BiblioDefaultView') eq 'isbd') { + if ( $total == 1 + && $format ne 'rss' + && $format ne 'opensearchdescription' + && $format ne 'atom' + && C4::Context->preference('RedirectToSoleResult') ) + { + my $biblionumber = $newresults[0]->{biblionumber}; + if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) { print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber"); - } elsif (C4::Context->preference('BiblioDefaultView') eq 'marc') { + } elsif ( C4::Context->preference('BiblioDefaultView') eq 'marc' ) { print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber"); } else { print $cgi->redirect("/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber"); - } + } exit; } if ($hits) { -- 2.30.2