From 1b16cf17bff5a0a78b4e230a4ec61141ce71b2a6 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 --- 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 e3da85daeee..fe7de8b01c5 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 ae864ee30cf..693572001e8 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