예제 #1
0
 /**
  * Add a document to the index by id
  * @param array[WPSearch_Document] $documents
  */
 public function addToIndex($document_ids)
 {
     if (!is_array($document_ids)) {
         $document_ids = array($document_ids);
     }
     $this->removeFromIndex($document_ids);
     $index = $this->_getIndex();
     foreach ($document_ids as $id) {
         # TODO: If you really need to doc multiple posts, do this in one call
         WPSearch_Log::add('debug', "Adding post #{$id} to index");
         $post = WPSearch_Model::getPublishedDocument($id);
         $categories = FALSE;
         $comments = FALSE;
         if ($this->_doesIndexCategories()) {
             $categories = $this->_getCategoriesAsStrings($id);
         }
         if ($this->_doesIndexComments()) {
             $comments = $this->_getCommentsAsString($id);
         }
         $index->addDocument($this->_createLuceneDocument($post, $categories, $comments));
     }
     $index->commit();
     $index->optimize();
 }