示例#1
0
 public function addDocument(Document $document)
 {
     try {
         $level = error_reporting(0);
         parent::addDocument($document);
     } catch (\Exception $e) {
         error_reporting($level);
     }
 }
 /**
  * Create Zend Lucene index
  */
 public function index()
 {
     foreach ($this->models as $key => $value) {
         $dataProvider = new ActiveDataProvider($value['dataProviderOptions']);
         $iterator = new DataProviderIterator($dataProvider);
         if (isset($value['attributes']['lang'])) {
             $hits = $this->luceneIndex->find('lang:' . $value['attributes']['lang']);
             foreach ($hits as $hit) {
                 $this->luceneIndex->delete($hit->id);
             }
         }
         foreach ($iterator as $model) {
             $document = $this->createDocument($model, $value['attributes']);
             $this->luceneIndex->addDocument($document);
         }
     }
     $this->luceneIndex->optimize();
     $this->luceneIndex->commit();
     return true;
 }
 /**
  * Add page to the index.
  * @param string $title
  * @param string $body
  * @param string $url
  */
 public function add($title, $body, $url)
 {
     $this->delete($url);
     $this->luceneIndex->addDocument($this->createDocument($title, $body, $url));
 }
 /**
  * Add document to the index.
  * @param array $fields ('name' => string, 'value' => string, ['type' => string])
  * Default type is 'text'.
  */
 public function add($fields)
 {
     $this->luceneIndex->addDocument($this->createDocument($fields));
 }