From 8a765c82a8badad19079dc4f1046ed7a6acd9fb5 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 12 Apr 2013 10:36:23 -0400
Subject: [PATCH] CollectionsController now uses search service.

---
 .../Controller/CollectionsController.php      | 24 +++++++------------
 .../templates/collections/bytitle.phtml       |  4 ++--
 .../templates/collections/bytitle.phtml       |  4 ++--
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/CollectionsController.php b/module/VuFind/src/VuFind/Controller/CollectionsController.php
index 1f1b4a7d1cd..ee8ed5f8dd4 100644
--- a/module/VuFind/src/VuFind/Controller/CollectionsController.php
+++ b/module/VuFind/src/VuFind/Controller/CollectionsController.php
@@ -26,6 +26,7 @@
  * @link     http://vufind.org   Main Site
  */
 namespace VuFind\Controller;
+use VuFindSearch\Query\Query;
 
 /**
  * Collections Controller
@@ -65,13 +66,11 @@ class CollectionsController extends AbstractBase
         $collections = $this->getCollectionsFromTitle(
             $this->params()->fromQuery('title')
         );
-        if (is_array($collections) && count($collections) != 1) {
-            $view = $this->createViewModel();
-            $view->collections = $collections;
-            return $view;
+        if (count($collections) != 1) {
+            return $this->createViewModel(array('collections' => $collections));
         }
         return $this->redirect()
-            ->toRoute('collection', array('id' => $collections[0]['id']));
+            ->toRoute('collection', array('id' => $collections[0]->getUniqueId()));
     }
 
     /**
@@ -331,17 +330,10 @@ class CollectionsController extends AbstractBase
      */
     protected function getCollectionsFromTitle($title)
     {
-        $db = \VuFind\Connection\Manager::connectToIndex();
         $title = addcslashes($title, '"');
-        $result = $db->search(
-            array(
-                'query' => "is_hierarchy_title:\"$title\"",
-                'handler' => 'AllFields',
-                'limit' => $this->getBrowseLimit()
-            )
-        );
-
-        return isset($result['response']['docs'])
-            ? $result['response']['docs'] : array();
+        $query = new Query("is_hierarchy_title:\"$title\"", 'AllFields');
+        $searchService = $this->getServiceLocator()->get('VuFind\Search');
+        $result = $searchService->search('Solr', $query, 0, $this->getBrowseLimit());
+        return $result->getRecords();
     }
 }
diff --git a/themes/blueprint/templates/collections/bytitle.phtml b/themes/blueprint/templates/collections/bytitle.phtml
index ec2c80a79b7..b79fdba8bb8 100644
--- a/themes/blueprint/templates/collections/bytitle.phtml
+++ b/themes/blueprint/templates/collections/bytitle.phtml
@@ -11,8 +11,8 @@
         <div id="disambiguationItemsDiv">
           <? foreach ($collections as $i => $collection): ?>
            <div class="disambiguationItem <?=$i % 2 ? 'alt ' : ''?>record<?=$i?>">
-             <a href="<?=$this->url('collection', array('id' => $collection['id']))?>"><?=$this->escapeHtml($collection['title'])?></a>
-             <p><?=$this->escapeHtml($collection['description'])?></p>
+             <a href="<?=$this->url('collection', array('id' => $collection->getUniqueId()))?>"><?=$this->escapeHtml($collection->getTitle())?></a>
+             <p><?=$this->escapeHtml(implode(' ', $collection->getSummary()))?></p>
            </div>
           <? endforeach; ?>
         </div>
diff --git a/themes/jquerymobile/templates/collections/bytitle.phtml b/themes/jquerymobile/templates/collections/bytitle.phtml
index 2a008fc838a..36b5b62e661 100644
--- a/themes/jquerymobile/templates/collections/bytitle.phtml
+++ b/themes/jquerymobile/templates/collections/bytitle.phtml
@@ -6,8 +6,8 @@
       <ul class="results" data-role="listview" data-split-icon="plus" data-split-theme="c">
         <? foreach ($collections as $i => $collection): ?>
          <li>
-           <a rel="external" href="<?=$this->url('collection', array('id' => $collection['id']))?>"><h3><?=$this->escapeHtml($collection['title'])?></h3>
-           <p><?=$this->escapeHtml($collection['description'])?></p>
+           <a rel="external" href="<?=$this->url('collection', array('id' => $collection->getUniqueId()))?>"><h3><?=$this->escapeHtml($collection->getTitle())?></h3>
+           <p><?=$this->escapeHtml(implode(' ', $collection->getSummary()))?></p>
            </a>
          </li>
         <? endforeach; ?>
-- 
GitLab