Exemple #1
0
 /**
  * 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();
 }
 /**
  * Remove  a post from the index
  *
  * @param Post $post the post being deleted
  */
 public function delete_post($post)
 {
     $term = new Zend_Search_Lucene_Index_Term($post->id, 'postid');
     $docIds = $this->_index->termDocs($term);
     foreach ($docIds as $id) {
         $this->_index->delete($id);
     }
 }
Exemple #3
0
 public static function removeFromIndex($term)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $searchIndexFolder = $websiteHelper->getPath() . 'cache/' . Widgets_Search_Search::INDEX_FOLDER;
     if (!is_dir($searchIndexFolder)) {
         return false;
     }
     if (!self::initIndex()) {
         return false;
     }
     $hits = self::$_index->find(strval($term));
     if (is_array($hits) && !empty($hits)) {
         foreach ($hits as $hit) {
             self::$_index->delete($hit->id);
         }
         return true;
     }
     return false;
 }
Exemple #4
0
 /**
  * Remove a record from the search index
  *
  * @param string $value
  * @param string $searchField
  * @return Zym_Search_Lucene_Index
  */
 public function delete($value, $searchField = null)
 {
     if (!$searchField) {
         $searchField = $this->_idKey;
     }
     $documentIds = $this->getDocumentIds($value, $searchField);
     foreach ($documentIds as $id) {
         $this->_searchIndex->delete($id);
     }
     return $this;
 }
 /**
  * Deletes a document from the index.
  * $id is an internal document id
  *
  * @param integer|Zend_Search_Lucene_Search_QueryHit $id
  * @throws Zend_Search_Lucene_Exception
  */
 public function delete($id)
 {
     return $this->_index->delete($id);
 }