/**
  * Debug method to allow manual reindexing with output via the URL 
  * /Lucene/reindex
  *
  * @access public
  * Note that this should NOT be used as a reindexing
  * process in production, as it doesn't allow for out of memory or script 
  * execution time problems.
  */
 public function reindex()
 {
     set_time_limit(600);
     $start = microtime(true);
     echo '<h1>Reindexing</h1>' . "\n";
     flush();
     echo 'Note that this process may die due to time limit or memory ' . 'exhaustion, and is purely for debugging purposes.  Use the ' . 'Queued Jobs reindex process for production indexing.' . "<br />\n<br />\n";
     flush();
     ZendSearchLuceneWrapper::getIndex(true);
     $indexable = ZendSearchLuceneWrapper::getAllIndexableObjects();
     foreach ($indexable as $item) {
         $obj = DataObject::get_by_id($item[0], $item[1]);
         if ($obj) {
             $obj_start = microtime(true);
             echo $item[0] . ' ' . $item[1] . ' (' . $obj->class . ')';
             flush();
             ZendSearchLuceneWrapper::index($obj);
             echo ' - ' . round(microtime(true) - $obj_start, 3) . ' seconds' . "<br />\n";
             flush();
         } else {
             echo 'Object ' . $item[0] . ' ' . $item[1] . ' was not found.' . "<br />\n";
             flush();
         }
     }
     echo "<br />\n" . 'Finished (' . round(microtime(true) - $start, 3) . ' seconds)' . "<br />\n";
     flush();
 }
 public function process()
 {
     $remainingDocuments = $this->remainingDocuments;
     // if there's no more, we're done!
     if (!count($remainingDocuments)) {
         $this->isComplete = true;
         return;
     }
     $this->currentStep++;
     $item = array_shift($remainingDocuments);
     $obj = DataObject::get_by_id($item[0], $item[1]);
     ZendSearchLuceneWrapper::index($obj);
     // and now we store the new list of remaining children
     $this->remainingDocuments = $remainingDocuments;
     if (!count($remainingDocuments)) {
         $this->isComplete = true;
         return;
     }
 }
 public function process()
 {
     // if there's no more, we're done!
     if (!count($this->jobData)) {
         $this->isComplete = true;
         $idx = ZendSearchLuceneWrapper::getIndex();
         $idx->optimize();
         return;
     }
     $this->currentStep++;
     $item = array_shift($this->jobData);
     $obj = DataObject::get_by_id($item[0], $item[1]);
     ZendSearchLuceneWrapper::index($obj);
     if (!count($this->jobData)) {
         $this->isComplete = true;
         $idx = ZendSearchLuceneWrapper::getIndex();
         $idx->optimize();
         return;
     }
 }
 /**
  * Indexes the object after it has been written to the database.
  */
 public function onAfterWrite()
 {
     // Obey index filter rules
     $objs = ZendSearchLuceneWrapper::getAllIndexableObjects($this->owner->ClassName);
     ZendSearchLuceneWrapper::delete($this->owner);
     foreach ($objs as $obj) {
         if (!is_object($obj)) {
             continue;
         }
         if (!is_object($this->owner)) {
             continue;
         }
         if ($obj[0] == $this->owner->class && $obj[1] == $this->owner->ID) {
             ZendSearchLuceneWrapper::index($this->owner);
         }
     }
     parent::onAfterWrite();
 }
 /**
  * Retrieves a Zend_Search_Lucene_Interface object connected to the search
  * index.
  * 
  * If the index does not exist, it is created.  On creation, any callbacks 
  * added using ZendSearchLuceneWrapper::addCreateIndexCallback() are run.
  * To use this feature, add your callback registration to your _config.php:
  *
  * <code>
  * function create_index_callback() {
  *     $index = ZendSeachLuceneWrapper::getIndex();
  *     $index->setMaxBufferedDocs(20);
  * }
  * ZendSearchLuceneWrapper::addCreateIndexCallback('create_index_callback');
  * </code>
  * 
  * The index lives in the directory specified by the $cacheDirectory static.
  * If the index already exists, it is opened, unless $forceCache is set
  * true, in which case the existing index is blanked and a new one created
  * in its place.  This is useful for re-indexing a site.
  * 
  * @param String $forceCreate Whether to force creation of the index even
  *          if it already exists.  Defaults to false, which opens the index
  *          if it exists.
  * @return Zend_Search_Lucene_Interface
  * @link http://zendframework.com/apidoc/1.10/Zend_Search_Lucene/Index/Zend_Search_Lucene_Interface.html
  */
 public static function getIndex($forceCreate = false)
 {
     if (!$forceCreate && !empty(self::$index)) {
         return self::$index;
     }
     $indexFilename = ZendSearchLuceneSearchable::$cacheDirectory . DIRECTORY_SEPARATOR . self::$indexName;
     if (!$forceCreate && file_exists($indexFilename)) {
         self::$index = Zend_Search_Lucene::open($indexFilename);
     } else {
         self::$index = Zend_Search_Lucene::create($indexFilename);
         // Call all callbacks registered via
         // ZendSearchLuceneWrapper::addCreateIndexCallback()
         foreach (self::$createIndexCallbacks as $callback) {
             call_user_func($callback);
         }
     }
     return self::$index;
 }