Bug 9578: avoid a search crash when attempting to sort results of invalid query
authorFridolyn SOMERS <fridolyn.somers@biblibre.com>
Fri, 22 Nov 2013 10:00:21 +0000 (11:00 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 13 Aug 2014 15:35:31 +0000 (11:35 -0400)
When searching with a sort (means not by relevance) and there is an error
in Zebra connexion (server is down or query is wrong), you get the message :

  Error : Can't call method "sort" on an undefined value at /home/kohaadmin/src/C4/Search.pm line 405.

This patch corrects by not performing sort if there are no no results.

Steps to reproduce the error without patch:

In OPAC go to Advanced Search
Choose "Title" in first "Search for:" end enter "ccl=( and )"
Display "More options"
Set "Sort by" to "Title (A-Z)"
Click "Search" at bootom of page

Result:
Error:
Can't call method "sort" on an undefined value at /usr/share/kohaclone/C4/Search.pm line 430.

After applying the patch, try that search again.  This time,
it should report not results found with out the error message.

Alternative Test plan :
- Set OPACdefaultSortField on something else than relevance
- Perform a simple search with a wrong CCL query. For example : ccl=( and )
=> You get the messge : No results found ...

Patch behaves as expected.
Signed-off-by: Marc VĂ©ron <veron@veron.ch>

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Adds another check to prevent a bad Zebra error message.
Works as described, passes all tests and QA script.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 3b402d04e1a321afac02da84bae12f0342b776ad)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 65f76726846e2e9dd38d80a8fa1891410f6100f2)

C4/Search.pm

index 884556f..0da15f5 100644 (file)
@@ -423,7 +423,7 @@ sub getRecords {
                 warn "Ignoring unrecognized sort '$sort' requested" if $sort_by;
             }
         }
-        if ($sort_by && !$scan) {
+        if ( $sort_by && !$scan && $results[$i] ) {
             if ( $results[$i]->sort( "yaz", $sort_by ) < 0 ) {
                 warn "WARNING sort $sort_by failed";
             }