Author: david
Date: Thu Feb  9 16:17:17 2012
New Revision: 10833

Log:
Extend QubitSearch.  Remove unmodified methods

Modified:
   trunk/lib/QubitSearchPdo.class.php

Modified: trunk/lib/QubitSearchPdo.class.php
==============================================================================
--- trunk/lib/QubitSearchPdo.class.php  Thu Feb  9 16:14:59 2012        (r10832)
+++ trunk/lib/QubitSearchPdo.class.php  Thu Feb  9 16:17:17 2012        (r10833)
@@ -17,76 +17,8 @@
  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-class QubitSearch extends xfIndexSingle
+class QubitSearchPdo extends QubitSearch
 {
-  // allow disabling search index via boolean flag
-  public $disabled = true;
-
-  /*
-   * Enable singleton creation via getInstance()
-   */
-  protected static $_instance;
-
-  public static function getInstance()
-  {
-    if (null === self::$_instance)
-    {
-      // if the ElasticSearch plugin is enabled, use that instead
-      if (in_array('qtElasticSearchPlugin', 
sfConfig::get('sf_enabled_modules')))
-      {
-        self::$_instance = new qtElasticSearchPlugin();
-      }
-      else
-      {
-        self::$_instance = new self();
-      }
-    }
-
-    return self::$_instance;
-  }
-
-  public function parse($query)
-  {
-    if (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      self::getInstance()->parse($query);
-      return;
-    }
-
-    $query = Zend_Search_Lucene_Search_QueryParser::parse($query, 'UTF-8');
-
-    if ($query instanceOf Zend_Search_Lucene_Search_Query_Insignificant) {
-        throw new Exception('No search terms specified.');
-    } elseif ($query instanceOf Zend_Search_Lucene_Search_Query_MultiTerm) {
-        throw new Exception('Error parsing search terms.');
-    }
-
-    return $query;
-  }
-
-  public function addTerm($text, $field)
-  {
-    return new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term($text, $field));
-  }
-
-  /**
-   * @see xfIndex
-   */
-  protected function initialize()
-  {
-    if (self::$_instance instanceof qtElasticSearchPlugin)
-    {
-      return;
-    }
-
-    $this->setEngine(new 
xfLuceneEngine(sfConfig::get('sf_data_dir').'/index'));
-    $this->getEngine()->open();
-    
Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
-  }
-
-  /**
-   * @see xfIndex
-   */
   public function qubitPopulate($options)
   {
     if (self::getInstance() instanceof qtElasticSearchPlugin)
@@ -202,268 +134,6 @@
     $this->getLogger()->log('Index populated in "'.round(microtime(true) - 
$start, 2).'" seconds.', $this->getName());
   }
 
-  public function optimize()
-  {
-    if (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      return;
-    }
-
-    $start = microtime(true);
-    $this->getLogger()->log('Optimizing index...', $this->getName());
-    $this->getEngine()->optimize();
-    $this->getLogger()->log('Index optimized in "' . round(microtime(true) - 
$start, 2) . '" seconds.', $this->getName());
-  }
-
-  public function enableBatch()
-  {
-    $this->getEngine()->enableBatchMode();
-  }
-
-  public function disableBatch()
-  {
-    $this->getEngine()->disableBatchMode();
-  }
-
-  /*
-   * ======================================================================
-   * In lieu of a service registry (the "right" way to implement these methods)
-   * we have engine-specific handling below here; these are based on Zend 
Lucene
-   * ======================================================================
-   */
-
-  /**
-   * Delete an existing document from the index
-   *
-   * @param integer $id object identifier
-   * @return void
-   */
-  public static function deleteById($id)
-  {
-    if (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      self::getInstance()->deleteById($id);
-      return;
-    }
-
-    // have to use another search object to perform the querying
-    $querier = new QubitSearch();
-    $query = new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term($id, 'id'));
-
-    foreach ($querier->getEngine()->getIndex()->find($query) as $hit)
-    {
-      self::getInstance()->getEngine()->getIndex()->delete($hit->id);
-    }
-  }
-
-  /**
-   * Delete an existing document from the index
-   *
-   * @param integer $id object identifier
-   * @param string $language ISO-639-1 code
-   * @return void
-   */
-  public static function deleteByIdLanguage($id, $language)
-  {
-    // have to use another search object to perform the querying
-    $querier = new QubitSearch();
-    $query = new Zend_Search_Lucene_Search_Query_MultiTerm;
-    $query->addTerm(new Zend_Search_Lucene_Index_Term($id, 'id'), true);
-    $query->addTerm(new Zend_Search_Lucene_Index_Term($language, 'culture'), 
true);
-
-    foreach ($querier->getEngine()->getIndex()->find($query) as $hit)
-    {
-      self::getInstance()->getEngine()->getIndex()->delete($hit->id);
-    }
-  }
-
-  /**
-   * Get list of currently enabled languages from config
-   *
-   * @return array enabled language codes and names
-   */
-  public static function getEnabledI18nLanguages()
-  {
-    //determine the currently enabled i18n languages
-    $enabledI18nLanguages = array();
-
-    foreach (sfConfig::getAll() as $setting => $value)
-    {
-      if (0 === strpos($setting, 'app_i18n_languages'))
-      {
-        $enabledI18nLanguages[substr($setting, 19)] = $value;
-      }
-    }
-
-    return $enabledI18nLanguages;
-  }
-
-  /**
-   * Get translated language codes
-   *
-   * @return array list of translated languages (ISO-639-1 code)
-   */
-  public static function getTranslatedLanguages(&$object)
-  {
-    $conn = Propel::getConnection();
-
-    // If this class has an i18n table
-    if (class_exists(get_class($object).'I18n'))
-    {
-      $i18nTableName = constant(get_class($object).'I18n::TABLE_NAME');
-
-      $stmt = $conn->prepare('SELECT culture FROM '.$i18nTableName.' WHERE id 
= ? GROUP BY culture');
-      $stmt->execute(array($object->id));
-
-      while ($row = $stmt->fetch())
-      {
-        $translatedLanguages[] = $row['culture'];
-      }
-
-      $stmt->closeCursor();
-      $conn->clearStatementCache();
-    }
-    else
-    {
-      $translatedLanguages = self::getEnabledI18nLanguages();
-    }
-
-    return $translatedLanguages;
-  }
-
-  /*
-   * ======================================================================
-   * ACTORS
-   * ======================================================================
-   */
-
-  public static function updateActorIndex($actor)
-  {
-    if (self::getInstance()->disabled)
-    {
-      return;
-    }
-    // Don't index root object
-    elseif ($actor::ROOT_ID == $actor->id)
-    {
-      return;
-    }
-    elseif (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      self::getInstance()->save($actor);
-      return;
-    }
-
-    self::deleteById($actor->id);
-    self::addActorIndex($actor);
-  }
-
-  public static function addActorIndex(QubitActor $actor)
-  {
-    // Don't index root object
-    if ($actor::ROOT_ID == $actor->id)
-    {
-      return;
-    }
-
-    foreach ($actor->actorI18ns as $actorI18n)
-    {
-      $doc = new Zend_Search_Lucene_Document;
-
-      $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $actor->id));
-      $doc->addField(Zend_Search_Lucene_Field::Keyword('className', 
$actor->className));
-      $doc->addField(Zend_Search_Lucene_Field::Keyword('culture', 
$actorI18n->culture));
-
-      if (isset($actorI18n->authorizedFormOfName))
-      {
-        
$doc->addField(Zend_Search_Lucene_Field::UnStored('authorizedFormOfName', 
$actorI18n->authorizedFormOfName));
-      }
-
-      // Add other forms of name for this culture
-      $criteria = new Criteria;
-      $criteria->addJoin(QubitOtherNameI18n::ID, QubitOtherName::ID);
-      $criteria->add(QubitOtherNameI18n::CULTURE, $actorI18n->culture);
-      $criteria->add(QubitOtherName::OBJECT_ID, $actor->id);
-
-      if (0 < count($otherNameI18ns = QubitOtherNameI18n::get($criteria)))
-      {
-        foreach ($otherNameI18ns as $otherNameI18n)
-        {
-          $otherNames[] = $otherNameI18n->name;
-        }
-
-        $doc->addField(Zend_Search_Lucene_Field::UnStored('otherFormsOfName', 
implode(' ', $otherNames)));
-      }
-
-      self::getInstance()->getEngine()->getIndex()->addDocument($doc);
-    }
-  }
-
-  /*
-   * ======================================================================
-   * INFORMATION OBJECTS
-   * ======================================================================
-   */
-
-  public static function deleteInformationObject($informationObject, $options 
= array())
-  {
-    if (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      self::getInstance()->delete($informationObject);
-      return;
-    }
-
-    if (0 < count($languages = 
self::getTranslatedLanguages($informationObject)))
-    {
-      foreach ($languages as $language)
-      {
-        self::deleteByIdLanguage($informationObject->id, $language);
-      }
-    }
-  }
-
-  public static function updateInformationObject($informationObject, $options 
= array())
-  {
-    if (self::getInstance()->disabled)
-    {
-      return;
-    }
-    // Only ROOT node should have no parent, don't index
-    elseif (null === $informationObject->parent)
-    {
-      return;
-    }
-    elseif (self::getInstance() instanceof qtElasticSearchPlugin)
-    {
-      self::getInstance()->save($informationObject);
-      return;
-    }
-
-    if (0 < count($languages = 
self::getTranslatedLanguages($informationObject)))
-    {
-      foreach ($languages as $language)
-      {
-        self::updateInformationObjectIndex($informationObject, $language, 
$options);
-      }
-    }
-  }
-
-  public static function updateInformationObjectIndex(QubitInformationObject 
$informationObject, $language, $options = array())
-  {
-    if (self::getInstance()->disabled)
-    {
-      return;
-    }
-    // Only ROOT node should have no parent, don't index
-    elseif (null === $informationObject->parent)
-    {
-      return;
-    }
-
-    self::deleteByIdLanguage($informationObject->id, $language);
-    self::addInformationObjectIndex($informationObject, $language, $options);
-  }
-
   public static function addInformationObjectIndex(QubitInformationObject 
$informationObject, $language, $options = array())
   {
     // Only ROOT node should have no parent, don't index

-- 
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.com/group/qubit-commits?hl=en.

Reply via email to