From 85282772999bd4bdd15051d771b82e0151e36855 Mon Sep 17 00:00:00 2001 From: ByWater Staff Date: Tue, 7 Jan 2014 10:19:37 -0700 Subject: [PATCH] Bug 11489 - OPAC search results in 404 error when the only search result is supressed If hidelostitems is enabled, and the result of an opac search is a single lost item, then the opac will display a 404 error, rather than a "no results" screen. Test Plan: 1) Catalog a record/item such that it is the only result for some search e.g. Give it the title 'zxcvb' 2) Enable hidelostitems 3) Mark this item as lost 4) Perform an OPAC search that should result in a redirect to this record 5) Notice you a redirected to a 404 error 6) Apply this patch 7) Repeat step 4 8) Note you new get a "No results found!" page instead --- opac/opac-search.pl | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 8604d0f..cb977b9 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -556,6 +556,7 @@ for (my $i=0;$i<@servers;$i++) { @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan, $results_hashref->{$server}->{"RECORDS"}); } + $hits = 0 unless @newresults; foreach my $res (@newresults) { @@ -610,7 +611,7 @@ for (my $i=0;$i<@servers;$i++) { } if ($results_hashref->{$server}->{"hits"}){ - $total = $total + $results_hashref->{$server}->{"hits"}; + $total = $total + $hits; } # Opac search history @@ -656,7 +657,7 @@ for (my $i=0;$i<@servers;$i++) { } } ## If there's just one result, redirect to the detail page - if ($total == 1 && $format ne 'rss2' + if ( @newresults && $total == 1 && $format ne 'rss2' && $format ne 'opensearchdescription' && $format ne 'atom') { my $biblionumber=$newresults[0]->{biblionumber}; if (C4::Context->preference('BiblioDefaultView') eq 'isbd') { -- 1.7.2.5