From c693dd13a508c87916bf3d596f5c0ab5940a5caf Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 8 Jul 2013 10:13:43 -0400
Subject: [PATCH] Smarter handler matching.

---
 .../VuFind/src/VuFind/Recommend/SearchObject.php   |  2 +-
 module/VuFind/src/VuFind/Search/Base/Options.php   | 14 +++++++++++---
 .../src/VuFind/View/Helper/Root/SearchTabs.php     |  2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/module/VuFind/src/VuFind/Recommend/SearchObject.php b/module/VuFind/src/VuFind/Recommend/SearchObject.php
index 0ce98a97f03..f8ca9d415e8 100644
--- a/module/VuFind/src/VuFind/Recommend/SearchObject.php
+++ b/module/VuFind/src/VuFind/Recommend/SearchObject.php
@@ -133,7 +133,7 @@ abstract class SearchObject implements RecommendInterface
         $params->setLimit($this->limit);
         $params->setBasicSearch(
             $lookfor,
-            $params->getOptions()->getBasicHandlerForLabel($typeLabel)
+            $params->getOptions()->getHandlerForLabel($typeLabel)
         );
 
         // Perform the search:
diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php
index 527a469245b..b33848b6dea 100644
--- a/module/VuFind/src/VuFind/Search/Base/Options.php
+++ b/module/VuFind/src/VuFind/Search/Base/Options.php
@@ -159,17 +159,25 @@ abstract class Options implements TranslatorAwareInterface
 
     /**
      * Given a label from the configuration file, return the name of the matching
-     * basic handler; return the default handler if no match is found.
+     * handler (basic checked first, then advanced); return the default handler
+     * if no match is found.
      *
      * @param string $label Label to search for
      *
      * @return string
      */
-    public function getBasicHandlerForLabel($label)
+    public function getHandlerForLabel($label)
     {
+        $label = $this->translate($label);
+
         $targetHandler = false;
         foreach ($this->getBasicHandlers() as $id => $currentLabel) {
-            if ($currentLabel == $label) {
+            if ($this->translate($currentLabel) == $label) {
+                return $id;
+            }
+        }
+        foreach ($this->getAdvancedHandlers() as $id => $currentLabel) {
+            if ($this->translate($currentLabel) == $label) {
                 return $id;
             }
         }
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php b/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php
index bd0e366725d..48f67b0865a 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php
@@ -142,7 +142,7 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
         $options = $results->getOptions();
 
         // Find matching handler for new query (and use default if no match):
-        $targetHandler = $options->getBasicHandlerForLabel(
+        $targetHandler = $options->getHandlerForLabel(
             $activeOptions->getLabelForBasicHandler($handler)
         );
 
-- 
GitLab