예제 #1
0
파일: Search.php 프로젝트: neolao/wiki
 /**
  * Index a file
  *
  * @param   string  $filePath   The file path
  */
 public function index($filePath)
 {
     $content = file_get_contents($filePath);
     $modificationTime = filemtime($filePath);
     $checksum = md5($content);
     // Get the document
     $hits = $this->_data->find('path:' . $filePath);
     if (count($hits) > 0) {
         $hit = $hits[0];
         $document = $hit->getDocument();
         // If the checksums are the same, no need to update
         if ($checksum === $document->checksum) {
             return;
         }
         // Delete the document
         $this->_data->delete($hit);
     }
     // Create a new document
     $document = new Zend_Search_Lucene_Document();
     $document->addField(Zend_Search_Lucene_Field::keyword('path', $filePath));
     $document->addField(Zend_Search_Lucene_Field::keyword('modificationTime', $modificationTime));
     $document->addField(Zend_Search_Lucene_Field::keyword('checksum', $checksum));
     $document->addField(Zend_Search_Lucene_Field::unStored('content', $content, 'utf-8'));
     $this->_data->addDocument($document);
     // Commit the changes
     $this->_data->commit();
     $this->_data->optimize();
 }
 /**
  * @param AJXP_Node $parentNode
  */
 public function indexationEnds($parentNode)
 {
     $this->logDebug('INDEX.END', 'Optimizing Index');
     $this->currentIndex->optimize();
     $this->logDebug('INDEX.END', 'Commiting Index');
     $this->currentIndex->commit();
     unset($this->currentIndex);
     $this->logDebug('INDEX.END', 'Merging Temporary in main');
     $this->mergeTemporaryIndexToMain($parentNode->getRepositoryId());
     $this->logDebug('INDEX.END', 'Done');
 }
예제 #3
0
 /**
  * Instanciate the Lucene index
  * 
  * The index will be created if it doesn't exist yet.
  * 
  * @return \Zend_Search_Lucene_Interface							Lucene index instance
  * @throws Exception											If the index cannot be created
  */
 protected function _index()
 {
     // One-time instanciation or creation of the lucene index
     if ($this->_index === null) {
         // Try to instanciate an existing lucene index
         try {
             $this->_index = \Zend_Search_Lucene::open($this->_indexDirectory);
             // If an error occurs ...
         } catch (\Zend_Search_Lucene_Exception $e) {
             // Try to create a new lucene index ...
             try {
                 $this->_index = \Zend_Search_Lucene::create($this->_indexDirectory);
                 // If an error occurs: Failure
             } catch (\Zend_Search_Lucene_Exception $e) {
                 throw new Exception(sprintf('Error creating lucene index in "%1$s", reason: "%2$s"', $this->_indexDirectory, $e->getMessage()));
             }
         }
         // Index setup
         \Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0664);
         \Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         \Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
         // Minimize memory consumption
         $this->_index->setMaxBufferedDocs(1);
         // Set optimization frequency
         $this->_index->setMergeFactor(max(1, intval($GLOBALS['TYPO3_CONF_VARS']['EXT']['extParams']['tw_lucenesearch']['mergeFactor'])));
         // If applicable: Optimize index
         if ($this->_indexOptimize) {
             $this->_index->optimize();
         }
         $this->_index->commit();
         if (TYPO3_MODE == 'FE') {
             \Zend_Search_Lucene::setTermsPerQueryLimit(\Tollwerk\TwLucenesearch\Utility\Indexer::indexConfig($GLOBALS['TSFE'], 'search.limits.query'));
         }
     }
     return $this->_index;
 }
예제 #4
0
 /**
  * Commit changes resulting from delete() or undeleteAll() operations.
  */
 public function commit()
 {
     $this->_index->commit();
 }
예제 #5
0
파일: Core.php 프로젝트: varvanin/currycms
 /**
  * Open the lucene search index and return it.
  *
  * @param bool $forceCreation
  * @return Zend_Search_Lucene_Interface
  */
 public static function getSearchIndex($forceCreation = false)
 {
     if (!self::$index || $forceCreation) {
         if (self::$index) {
             self::$index->commit();
             self::$index = null;
         }
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding(self::$config->curry->internalEncoding);
         $path = Curry_Util::path(self::$config->curry->projectPath, 'data', 'searchindex');
         self::$index = $forceCreation ? Zend_Search_Lucene::create($path) : Zend_Search_Lucene::open($path);
     }
     return self::$index;
 }