Ejemplo n.º 1
0
 public function edit($needFields = array(), $data = array(), $charset = 'UTF-8')
 {
     $index = new Zend_Search_Lucene(ZY_ROOT . '/index');
     $doc = new Zend_Search_Lucene_Document();
     foreach ($needFields as $key => $field) {
         switch ($field) {
             case 'keywords':
                 $doc->addField(Zend_Search_Lucene_Field::Keyword($key, $data[$key], $charset));
                 break;
             case 'text':
                 $doc->addField(Zend_Search_Lucene_Field::Text($key, $data[$key], $charset));
                 break;
             case 'unindexed':
                 $doc->addField(Zend_Search_Lucene_Field::unindexed($key, $data[$key], $charset));
                 break;
             default:
                 $doc->addField(Zend_Search_Lucene_Field::$field($key, $data[$key], $charset));
                 break;
         }
     }
     $index->addDocument($doc);
     $index->commit();
     $index->optimize();
     return TRUE;
 }
 public function optimizeIndex()
 {
     // optimize lucene index for better performance
     $this->index->optimize();
     //clean up
     if (is_object($this->index) and $this->index instanceof \Zend_Search_Lucene_Proxy) {
         $this->index->removeReference();
         unset($this->index);
         \Pimcore\Logger::debug('LuceneSearch: Closed frontend index references');
     }
     \Pimcore\Logger::debug('LuceneSearch: optimizeIndex.');
 }
 /**
  * removeFromIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function removeFromIndex($strIndexPath, $strKey)
 {
     try {
         if (count(scandir($strIndexPath)) > 2) {
             $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key');
             $objQuery = new Zend_Search_Lucene_Search_Query_Term($objTerm);
             $objHits = $this->objIndex->find($objQuery);
             foreach ($objHits as $objHit) {
                 $this->objIndex->delete($objHit->id);
             }
             $this->objIndex->commit();
             $this->objIndex->optimize();
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
 /**
  * removeFromIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function removeFromIndex($strIndexPath, $strKey)
 {
     try {
         $this->core->logger->debug('massiveart->generic->data->types->GenericDataTypeAbstract->removeFromIndex(' . $strIndexPath . ', ' . $strKey . ')');
         if (count(scandir($strIndexPath)) > 2) {
             $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key');
             $objQuery = strpos($strKey, '*') !== false ? new Zend_Search_Lucene_Search_Query_Wildcard($objTerm) : new Zend_Search_Lucene_Search_Query_Term($objTerm);
             $objHits = $this->objIndex->find($objQuery);
             foreach ($objHits as $objHit) {
                 $this->objIndex->delete($objHit->id);
             }
             $this->objIndex->commit();
             $this->objIndex->optimize();
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
Ejemplo n.º 5
0
 /**
  * Optimise the lucene index.
  * This can be called periodically to optimise performance and size of the lucene index.
  *
  */
 public function optimise()
 {
     parent::optimise();
     $this->lucene->optimize();
 }
Ejemplo n.º 6
0
 private function updateIndex()
 {
     $models = array('ConceptualDomain', 'DataElement', 'DataElementConcept', 'Dimensionality', 'NonEnumeratedConceptualDomain', 'NonEnumeratedValueDomain', 'ObjectClass', 'Property', 'UnitOfMeasure', 'Value', 'ValueDomain', 'ValueMeaning');
     foreach ($models as $model) {
         $modelName = $this->modelPrefix . $model;
         $m = new $modelName();
         $values = $m->fetchAll();
         foreach ($values as $value) {
             $valuesArray = $value->toArray();
             $url = $this->view->url(array('module' => 'default', 'controller' => 'Index', 'action' => 'edit', 'model' => $model, 'id' => $valuesArray[$m->getPrimaryKey()]), '', true);
             $this->addEntryToSearchIndex($url, $valuesArray);
         }
     }
     $options = $this->getInvokeArg('bootstrap')->getOption('lucene');
     $luceneDir = $options['dir'];
     $doc = new Zend_Search_Lucene_Document();
     $index = new Zend_Search_Lucene($luceneDir);
     $index->optimize();
 }
Ejemplo n.º 7
0
 /**
  * Search index creation
  */
 public function actionCreate()
 {
     /**
      * Если это не AJAX-запрос - посылаем:
      **/
     if (!Yii::app()->getRequest()->getIsPostRequest() && !Yii::app()->getRequest()->getIsAjaxRequest()) {
         throw new CHttpException(404, Yii::t('ZendSearchModule.zendsearch', 'Page was not found!'));
     }
     try {
         // Папка для хранения индекса поиска
         $indexFiles = Yii::app()->getModule('zendsearch')->indexFiles;
         // Модели, включенные в индекс
         $searchModels = Yii::app()->getModule('zendsearch')->searchModels;
         // Лимит количества символов к описанию превью найденной страницы
         $limit = 600;
         SetLocale(LC_ALL, 'ru_RU.UTF-8');
         $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
         Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $indexFiles), true);
         $messages = [];
         if (extension_loaded('iconv') === true) {
             // Пробежаться по всем моделям и добавить их в индекс
             foreach ($searchModels as $modelName => $model) {
                 if (!empty($model['path'])) {
                     Yii::import($model['path']);
                 }
                 if (!isset($model['module'])) {
                     $messages[] = Yii::t('ZendSearchModule.zendsearch', 'Update config file or module, Module index not found for model "{model}"!', ['{model}' => $modelName]);
                 } elseif (is_file(Yii::getPathOfAlias($model['path']) . '.php') && Yii::app()->hasModule($model['module'])) {
                     $criteria = isset($model['criteria']) ? $model['criteria'] : [];
                     $searchNodes = $modelName::model()->findAll(new CDbCriteria($criteria));
                     foreach ($searchNodes as $node) {
                         $doc = new Zend_Search_Lucene_Document();
                         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($node->{$model}['titleColumn']), 'UTF-8'));
                         $link = str_replace('{' . $model['linkColumn'] . '}', $node->{$model}['linkColumn'], $model['linkPattern']);
                         $doc->addField(Zend_Search_Lucene_Field::Text('link', $link, 'UTF-8'));
                         $contentColumns = explode(',', $model['textColumns']);
                         $i = 0;
                         foreach ($contentColumns as $column) {
                             $content = $this->cleanContent($node->{$column});
                             if ($i == 0) {
                                 $doc->addField(Zend_Search_Lucene_Field::Text('content', $content, 'UTF-8'));
                                 $description = $this->cleanContent($this->previewContent($node->{$column}, $limit));
                                 $doc->addField(Zend_Search_Lucene_Field::Text('description', $description, 'UTF-8'));
                             } else {
                                 $doc->addField(Zend_Search_Lucene_Field::Text('content' . $i, $content, 'UTF-8'));
                             }
                             $i++;
                         }
                         $index->addDocument($doc);
                     }
                     $index->optimize();
                     $index->commit();
                 } else {
                     $messages[] = Yii::t('ZendSearchModule.zendsearch', 'Module "{module}" not installed!', ['{module}' => $model['module']]);
                 }
             }
         } else {
             $messages[] = Yii::t('ZendSearchModule.zendsearch', 'This module require "Iconv" extension!');
         }
         Yii::app()->ajax->raw(empty($messages) ? Yii::t('ZendSearchModule.zendsearch', 'Index updated successfully!') : Yii::t('ZendSearchModule.zendsearch', 'There is an error!') . ': ' . implode("\n", $messages));
     } catch (Exception $e) {
         Yii::app()->ajax->raw(Yii::t('ZendSearchModule.zendsearch', 'There is an error!') . ":\n" . $e->getMessage());
     }
 }