Author: jablko
Date: Thu Aug 27 11:30:58 2009
New Revision: 3083

Log:
Use search index for actor and repository lists

Modified:
   trunk/apps/qubit/modules/actor/actions/listAction.class.php
   trunk/apps/qubit/modules/actor/templates/listSuccess.php
   trunk/apps/qubit/modules/repository/actions/listAction.class.php
   trunk/apps/qubit/modules/repository/templates/listSuccess.php

Modified: trunk/apps/qubit/modules/actor/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/actor/actions/listAction.class.php Thu Aug 27 
11:27:09 2009        (r3082)
+++ trunk/apps/qubit/modules/actor/actions/listAction.class.php Thu Aug 27 
11:30:58 2009        (r3083)
@@ -66,25 +66,19 @@
 
   protected function htmlResponse($request)
   {
-    $options = array();
+    $search = new QubitSearch;
+    $query = new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term('QubitActor', 'className'));
 
-    // Set culture and cultural fallback flag
-    $this->culture = $this->getUser()->getCulture();
-    $options['cultureFallback'] = true; // Do cultural fallback
+    $this->pager = new 
QubitSearchPager($search->getEngine()->getIndex()->find($query), 
$request->page);
 
-    // Set sort
-    $this->sort = $this->getRequestParameter('sort', 'nameUp');
-    $options['sort'] = $this->sort;
-
-    // Set current page
-    $this->page = $this->getRequestParameter('page', 1);
-    $options['page'] = $this->page;
-
-    // Set role
-    $this->role = $this->getRequestParameter('role', 'all');
-    $options['role'] = $this->role;
-
-    // Get results
-    $this->actors = QubitActor::getList($options);
+    $ids = array();
+    foreach ($this->pager->getHits() as $hit)
+    {
+      $ids[] = $hit->getDocument()->id;
+    }
+
+    $criteria = new Criteria;
+    $criteria->add(QubitActor::ID, $ids, Criteria::IN);
+    $this->actors = QubitActor::get($criteria);
   }
 }

Modified: trunk/apps/qubit/modules/actor/templates/listSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/actor/templates/listSuccess.php    Thu Aug 27 
11:27:09 2009        (r3082)
+++ trunk/apps/qubit/modules/actor/templates/listSuccess.php    Thu Aug 27 
11:30:58 2009        (r3083)
@@ -25,7 +25,7 @@
       <?php echo image_tag('up.gif', array('style' => 'padding-bottom: 3px'), 
'sort up') ?>
     <?php endif; ?>
   </th>
-</tr></thead><tbody><?php foreach ($actors->getResults() as $actor): ?><tr>
+</tr></thead><tbody><?php foreach ($actors as $actor): ?><tr>
   <td>
 
     <div>
@@ -42,22 +42,20 @@
     </td>
 </tr><?php endforeach; ?></tbody></table>
 
-<?php if ($actors->haveToPaginate()): ?>
+<?php if ($pager->haveToPaginate()): ?>
 <div class="pager">
-  <?php $links = $actors->getLinks(); ?>
-  <?php if ($actors->getPage() != $actors->getFirstPage()): ?>
- <?php echo link_to('< '.__('previous'), array('page' => $actors->getPage() - 
1) + $sf_request->getParameterHolder()->getAll()) ?>
+  <?php if (1 != $pager->getCurrentPage()): ?>
+ <?php echo link_to('< '.__('previous'), array('page' => 
$pager->getCurrentPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
   <?php endif; ?>
-  <?php foreach ($links as $page): ?>
-    <?php echo ($page == $actors->getPage()) ? '<strong>'.$page.'</strong>' : 
link_to($page, array('page' => $page) + 
$sf_request->getParameterHolder()->getAll()) ?>
-    <?php if ($page != $actors->getCurrentMaxLink()): ?> <?php endif ?>
+  <?php foreach ($pager->getPages() as $page): ?>
+    <?php echo ($pager->getCurrentPage() == $page) ? 
'<strong>'.$page.'</strong>' : link_to($page, array('page' => $page) + 
$sf_request->getParameterHolder()->getAll()) ?>
   <?php endforeach ?>
-  <?php if ($actors->getPage() != $actors->getLastPage()): ?>
- <?php echo link_to(__('next').' >', array('page' => $actors->getPage() + 1) + 
$sf_request->getParameterHolder()->getAll()) ?>
+  <?php if (count($pager->getPages()) > $pager->getCurrentPage()): ?>
+ <?php echo link_to(__('next').' >', array('page' => $pager->getCurrentPage() 
+ 1) + $sf_request->getParameterHolder()->getAll()) ?>
   <?php endif; ?>
 </div>
 <?php endif ?>
 
 <div class="result-count">
-<?php echo __('displaying %1% to %2% of %3% results', array('%1%' => 
$actors->getFirstIndice(), '%2%' => $actors->getLastIndice(), '%3%' => 
$actors->getNbResults())) ?>
+<?php echo __('displaying %1% to %2% of %3% results', array('%1%' => 
$pager->getFirstHit(), '%2%' => $pager->getLastHit(), '%3%' => 
count($pager->getHits()))) ?>
 </div>

Modified: trunk/apps/qubit/modules/repository/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/repository/actions/listAction.class.php    Thu Aug 
27 11:27:09 2009        (r3082)
+++ trunk/apps/qubit/modules/repository/actions/listAction.class.php    Thu Aug 
27 11:30:58 2009        (r3083)
@@ -33,28 +33,19 @@
    */
   public function execute($request)
   {
-    $options = array();
-    $this->country = 0;
+    $search = new QubitSearch;
+    $query = new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term('QubitRepository', 'className'));
 
-    // Set culture and cultural fallback flag
-    $options['cultureFallback'] = true; // Do cultural fallback
+    $this->pager = new 
QubitSearchPager($search->getEngine()->getIndex()->find($query), 
$request->page);
 
-    // Set sort
-    $this->sort = $this->getRequestParameter('sort', 'nameUp');
-    $options['sort'] = $this->sort;
-
-    // Set current page
-    $this->page = $this->getRequestParameter('page', 1);
-    $options['page'] = $this->page;
-
-    // Filter by country
-    if ($this->getRequestParameter('country'))
+    $ids = array();
+    foreach ($this->pager->getHits() as $hit)
     {
-      $this->country = strtoupper($this->getRequestParameter('country'));
-      $options['countryCode'] = $this->country;
+      $ids[] = $hit->getDocument()->id;
     }
 
-    // Get repository hitlist
-    $this->repositories = QubitRepository::getList($options);
+    $criteria = new Criteria;
+    $criteria->add(QubitRepository::ID, $ids, Criteria::IN);
+    $this->repositories = QubitRepository::get($criteria);
   }
 }

Modified: trunk/apps/qubit/modules/repository/templates/listSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/repository/templates/listSuccess.php       Thu Aug 
27 11:27:09 2009        (r3082)
+++ trunk/apps/qubit/modules/repository/templates/listSuccess.php       Thu Aug 
27 11:30:58 2009        (r3083)
@@ -56,7 +56,7 @@
 </tr>
 </thead>
 <tbody>
-<?php foreach ($repositories->getResults() as $repository): ?>
+<?php foreach ($repositories as $repository): ?>
 <tr>
   <td>
   <?php $repositoryName = 
$repository->getAuthorizedFormOfName(array('cultureFallback' => true)); ?>
@@ -77,22 +77,20 @@
 </tbody>
 </table>
 
-<?php if ($repositories->haveToPaginate()): ?>
+<?php if ($pager->haveToPaginate()): ?>
 <div class="pager">
-  <?php $links = $repositories->getLinks(); ?>
-  <?php if ($repositories->getPage() != $repositories->getFirstPage()): ?>
- <?php echo link_to('< '.__('previous'), array('page' => 
$repositories->getPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
+  <?php if (1 != $pager->getCurrentPage()): ?>
+ <?php echo link_to('< '.__('previous'), array('page' => 
$pager->getCurrentPage() - 1) + $sf_request->getParameterHolder()->getAll()) ?>
   <?php endif; ?>
-  <?php foreach ($links as $page): ?>
-    <?php echo ($page == $repositories->getPage()) ? 
'<strong>'.$page.'</strong>' : link_to($page, array('page' => $page) + 
$sf_request->getParameterHolder()->getAll()) ?>
-    <?php if ($page != $repositories->getCurrentMaxLink()): ?> <?php endif ?>
+  <?php foreach ($pager->getPages() as $page): ?>
+    <?php echo ($pager->getCurrentPage() == $page) ? 
'<strong>'.$page.'</strong>' : link_to($page, array('page' => $page) + 
$sf_request->getParameterHolder()->getAll()) ?>
   <?php endforeach ?>
-  <?php if ($repositories->getPage() != $repositories->getLastPage()): ?>
- <?php echo link_to(__('next').' >', array('page' => $repositories->getPage() 
+ 1) + $sf_request->getParameterHolder()->getAll()) ?>
+  <?php if (count($pager->getPages()) != $pager->getCurrentPage()): ?>
+ <?php echo link_to(__('next').' >', array('page' => $pager->getCurrentPage() 
+ 1) + $sf_request->getParameterHolder()->getAll()) ?>
   <?php endif; ?>
 </div>
 <?php endif ?>
 
 <div class="result-count">
-<?php echo __('displaying %1% to %2% of %3% results', array('%1%' => 
$repositories->getFirstIndice(), '%2%' => $repositories->getLastIndice(), '%3%' 
=> $repositories->getNbResults())) ?>
+<?php echo __('displaying %1% to %2% of %3% results', array('%1%' => 
$pager->getFirstHit(), '%2%' => $pager->getLastHit(), '%3%' => 
count($pager->getHits()))) ?>
 </div>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to