public function del($field, $id) { $index = new Zend_Search_Lucene(ZY_ROOT . '/index'); $keywords = $field . ":" . $id; $hits = $index->find($keywords); foreach ($hits as $hit) { $index->delete($hit->id); } $index->commit(); return TRUE; }
/** * Removes a document from the index. * * @param int $docid * @return array containing (content, discussion, title) */ public function deleteDocument($docid) { $content = ''; $discussion = ''; $query = Zend_Search_Lucene_Search_QueryParser::parse('DocumentID:' . PHPLuceneIndexer::longToString($docid)); $hits = $this->lucene->find($query); // there should only be one, but we'll loop for safety foreach ($hits as $hit) { $content = $hit->Content; $discussion = $hit->Discussion; $title = $hit->Title; $version = $hit->Version; $this->lucene->delete($hit); } return array($content, $discussion, $title, $version); }
/** * removeFromIndex * @param string $strIndexPath * @param string $strKey * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected final function removeFromIndex($strIndexPath, $strKey) { try { if (count(scandir($strIndexPath)) > 2) { $this->objIndex = Zend_Search_Lucene::open($strIndexPath); $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key'); $objQuery = new Zend_Search_Lucene_Search_Query_Term($objTerm); $objHits = $this->objIndex->find($objQuery); foreach ($objHits as $objHit) { $this->objIndex->delete($objHit->id); } $this->objIndex->commit(); $this->objIndex->optimize(); } } catch (Exception $exc) { $this->core->logger->err($exc); } }
/** * removeFromIndex * @param string $strIndexPath * @param string $strKey * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected final function removeFromIndex($strIndexPath, $strKey) { try { $this->core->logger->debug('massiveart->generic->data->types->GenericDataTypeAbstract->removeFromIndex(' . $strIndexPath . ', ' . $strKey . ')'); if (count(scandir($strIndexPath)) > 2) { $this->objIndex = Zend_Search_Lucene::open($strIndexPath); $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key'); $objQuery = strpos($strKey, '*') !== false ? new Zend_Search_Lucene_Search_Query_Wildcard($objTerm) : new Zend_Search_Lucene_Search_Query_Term($objTerm); $objHits = $this->objIndex->find($objQuery); foreach ($objHits as $objHit) { $this->objIndex->delete($objHit->id); } $this->objIndex->commit(); $this->objIndex->optimize(); } } catch (Exception $exc) { $this->core->logger->err($exc); } }
$records = get_records_sql($query); if (is_array($records)) { foreach ($records as $record) { $updates[] = $delete_function($record->docid, $docIds[$record->docid]); } } } foreach ($updates as $update) { ++$update_count; //delete old document $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}"); //get the record, should only be one foreach ($doc as $thisdoc) { mtrace(" Delete: {$thisdoc->title} (database id = {$thisdoc->dbid}, index id = {$thisdoc->id}, moodle instance id = {$thisdoc->docid})"); $dbcontrol->delDocument($thisdoc); $index->delete($thisdoc->id); } //add new modified document back into index if (!($add = $get_document_function($update->id, $update->itemtype))) { // ignore on errors continue; } //object to insert into db $dbid = $dbcontrol->addDocument($add); //synchronise db with index $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid)); mtrace(" Add: {$add->title} (database id = {$add->dbid}, moodle instance id = {$add->docid})"); $index->addDocument($add); } } else { mtrace("No types to update.\n");
/** * Delete a hit. This can be useful for dynamically purging stuff. */ public function deleteHit($hit) { $this->index->delete($hit->id); }
private function updateEntryInSearch($url, array $content = null) { $options = $this->getInvokeArg('bootstrap')->getOption('lucene'); $index = new Zend_Search_Lucene($options['dir']); $hits = $index->find('url:' . $url); foreach ($hits as $hit) { $index->delete($hit->id); } if (!$content) { return; } else { $this->addEntryToSearchIndex($url, $content); } }
/** * This will refresh the search index for this topic (for all message content under this topic) * @param Zend_Search_Lucene $objIndex should be null if we are updating just one -- but for bulk index updates, you can pass in an already loaded index file * @return void */ public function RefreshSearchIndex($objIndex = null) { // Currently only implemented for Forum-based topic/message searches if ($this->TopicLink->TopicLinkTypeId != TopicLinkType::Forum) { return; } if (!$objIndex) { $objIndex = new Zend_Search_Lucene(__SEARCH_INDEXES__ . '/topics'); $blnIndexProvided = false; } else { $blnIndexProvided = true; } // Retrievew the Index Documents (if applicable) to delete them from the index $objSearchTerm = new Zend_Search_Lucene_Index_Term($this->Id, 'db_id'); foreach ($objIndex->termDocs($objSearchTerm) as $intDocId) { $objIndex->delete($intDocId); } // Create the Message Contents for this Topic $strContents = null; foreach ($this->GetMessageArray(QQ::OrderBy(QQN::Message()->ReplyNumber)) as $objMessage) { $strMessage = strip_tags(trim($objMessage->CompiledHtml)); $strMessage = html_entity_decode($strMessage, ENT_QUOTES, 'UTF-8'); $strContents .= $strMessage . "\r\n\r\n"; } // Create the Document $objDocument = new Zend_Search_Lucene_Document(); $objDocument->addField(Zend_Search_Lucene_Field::Keyword('db_id', $this->Id)); $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('topic_link_id', $this->TopicLinkId)); $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('topic_link_type_id', $this->TopicLink->TopicLinkTypeId)); $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('message_count', $this->MessageCount)); $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('last_post_date', $this->LastPostDate->Timestamp)); $objDocument->addField(Zend_Search_Lucene_Field::Text('title', $this->Name)); $objDocument->addField(Zend_Search_Lucene_Field::UnStored('contents', trim($strContents))); // Add Document to Index $objIndex->addDocument($objDocument); // Only call commit on the index if it was provided for us if (!$blnIndexProvided) { $objIndex->commit(); } }