Author: jablko
Date: Sun Aug 23 16:13:20 2009
New Revision: 3059

Log:
Get index from sfSearchPlugin. Rename QubitSearch::configure() -> 
QubitSearch::initialize() and add call to $this->getEngine()->open() to open 
index on instantiation.

Modified:
   trunk/apps/qubit/lib/SearchIndex.class.php
   trunk/apps/qubit/modules/search/actions/searchAction.class.php
   trunk/lib/search/QubitSearch.class.php

Modified: trunk/apps/qubit/lib/SearchIndex.class.php
==============================================================================
--- trunk/apps/qubit/lib/SearchIndex.class.php  Sun Aug 23 16:06:49 2009        
(r3058)
+++ trunk/apps/qubit/lib/SearchIndex.class.php  Sun Aug 23 16:13:20 2009        
(r3059)
@@ -28,36 +28,6 @@
  */
 class SearchIndex
 {
-  protected static
-    $index;
-
-  /**
-   * Get the location for the appropriate search index
-   *
-   * @param string $classname
-   * @param string $language ISO-639-1 language code
-   * @return void
-   */
-  public static function getIndexLocation($classname, $language = 'en')
-  {
-    return sfConfig::get('sf_data_dir').'/index';
-  }
-
-  public static function openIndex($classname, $language = 'en')
-  {
-    $indexLoc = self::getIndexLocation($classname, $language);
-    if (file_exists($indexLoc))
-    {
-      self::$index = Zend_Search_Lucene::open($indexLoc);
-    }
-    else
-    {
-      self::$index = Zend_Search_Lucene::create($indexLoc);
-    }
-
-    return self::$index;
-  }
-
   /**
    * Wrapper for selecting proper search index analyzer
    *
@@ -132,7 +102,6 @@
    */
   public static function updateTranslatedLanguages($object)
   {
-    self::openIndex(self::getIndexLocation(get_class($object)));
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new 
Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num());
 
     foreach (self::getTranslatedLanguages($object) as $languageCode)
@@ -173,10 +142,12 @@
    */
   public static function deleteIndexDocument($object, $language)
   {
+    $search = new QubitSearch;
+
     $query = new Zend_Search_Lucene_Search_Query_MultiTerm;
     $query->addTerm(new Zend_Search_Lucene_Index_Term($object->id, 
'objectId'), true);
     $query->addTerm(new Zend_Search_Lucene_Index_Term($language, 'culture'), 
true);
-    foreach (self::$index->find($query) as $hit)
+    foreach ($search->getEngine()->getIndex()->find($query) as $hit)
     {
       self::$index->delete($hit->id);
     }
@@ -190,7 +161,6 @@
    */
   public static function deleteTranslatedLanguages($object)
   {
-    self::openIndex(self::getIndexLocation(get_class($object)));
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(self::getIndexAnalyzer());
 
     foreach (self::getEnabledI18nLanguages() as $code => $language)
@@ -211,12 +181,14 @@
     // first delete existing index entries
     self::deleteIndexDocument($object, $language);
 
+    $search = new QubitSearch;
+
     // create and add document to index
     $doc = self::createIndexDocument($object, $language);
 
     if (null !== $doc)
     {
-      self::$index->addDocument($doc);
+      $search->getEngine()->getIndex()->addDocument($doc);
     }
   }
 

Modified: trunk/apps/qubit/modules/search/actions/searchAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/searchAction.class.php      Sun Aug 
23 16:06:49 2009        (r3058)
+++ trunk/apps/qubit/modules/search/actions/searchAction.class.php      Sun Aug 
23 16:13:20 2009        (r3059)
@@ -26,20 +26,20 @@
 
     $this->getResponse()->setTitle('Search for \''.$request->query.'\'', true);
 
-    $search_index = SearchIndex::getIndexLocation('informationobject', 
$culture);
     
Zend_Search_Lucene_Analysis_Analyzer::setDefault(SearchIndex::getIndexAnalyzer());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
 
     $this->hits = array();
 
+    $search = new QubitSearch;
+
     $query = new Zend_Search_Lucene_Search_Query_Boolean;
     $query->addSubquery(new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term($culture, 'culture')), true);
 
-    $index = Zend_Search_Lucene::open($search_index);
     $parser = new Zend_Search_Lucene_Search_QueryParser;
     $c = $parser->parse(strtolower($request->query), 'UTF-8');
     $query->addSubquery($c, true);
-    $this->hits = $index->find($query);
+    $this->hits = $search->getEngine()->getIndex()->find($query);
 
     // send results through pagination
     if ($this->getRequestParameter('page'))

Modified: trunk/lib/search/QubitSearch.class.php
==============================================================================
--- trunk/lib/search/QubitSearch.class.php      Sun Aug 23 16:06:49 2009        
(r3058)
+++ trunk/lib/search/QubitSearch.class.php      Sun Aug 23 16:13:20 2009        
(r3059)
@@ -22,8 +22,9 @@
   /**
    * @see xfIndex
    */
-  protected function configure()
+  protected function initialize()
   {
     $this->setEngine(new 
xfLuceneEngine(sfConfig::get('sf_data_dir').'/index'));
+    $this->getEngine()->open();
   }
 }

--~--~---------~--~----~------------~-------~--~----~
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