예제 #1
0
 public function addDocument(Document $document)
 {
     try {
         $level = error_reporting(0);
         parent::addDocument($document);
     } catch (\Exception $e) {
         error_reporting($level);
     }
 }
예제 #2
0
 /**
  * Search page for the term in the index.
  *
  * @param $term
  * @param array $fields
  * @return array|\ZendSearch\Lucene\Search\QueryHit
  */
 public function search($term, $fields = [])
 {
     Wildcard::setMinPrefixLength($this->minPrefixLength);
     Lucene::setResultSetLimit($this->resultsLimit);
     $query = new MultiTerm();
     if (count($fields)) {
         foreach ($fields as $field => $value) {
             $query->addTerm(new IndexTerm($value, $field), true);
         }
     }
     $subTerm = explode(' ', $term);
     foreach ($subTerm as $value) {
         $query->addTerm(new IndexTerm($value), true);
     }
     return $this->luceneIndex->find($query);
 }
예제 #3
0
 /**
  * Get segments file name
  *
  * @param integer $generation
  * @return string
  */
 public static function getSegmentFileName($generation)
 {
     return Index::getSegmentFileName($generation);
 }
예제 #4
0
 /**
  * Get name for new segment
  *
  * @return string
  */
 private function _newSegmentName()
 {
     Lucene\LockManager::obtainWriteLock($this->_directory);
     $generation = Lucene\Index::getActualGeneration($this->_directory);
     $segmentsFile = $this->_directory->getFileObject(Lucene\Index::getSegmentFileName($generation), false);
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentNameCounter = $segmentsFile->readInt();
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentsFile->writeInt($segmentNameCounter + 1);
     // Flash output to guarantee that wrong value will not be loaded between unlock and
     // return (which calls $segmentsFile destructor)
     $segmentsFile->flush();
     Lucene\LockManager::releaseWriteLock($this->_directory);
     return '_' . base_convert($segmentNameCounter, 10, 36);
 }
예제 #5
0
 /**
  * Full index optimization.
  * Each index segment is entirely independent portion of data.
  * So indexes containing more segments need more memory and time for searching.
  * Index optimization is a process of merging several segments into a new one.
  * Index optimization works with data streams and doesn't
  * take a lot of memory but does require processor resources and time.
  */
 public function optimize()
 {
     $this->luceneIndex->optimize();
 }
 /**
  * Remove the existing entry for the given Document from the index, if it exists.
  *
  * @param Lucene\Index $index The Zend Lucene Index
  * @param string $hash
  */
 private function removeExisting(Lucene\Index $index, $hash)
 {
     try {
         $hits = $index->find(self::HASH_FIELDNAME . ':' . $hash);
         foreach ($hits as $hit) {
             $index->delete($hit->id);
         }
     } catch (\Exception $ex) {
         // FIXME no result ???
     }
 }