From 7c5f078854757674bc420464f8e6b39b629a2761 Mon Sep 17 00:00:00 2001 From: conradverm Date: Tue, 18 Dec 2007 11:06:27 +0000 Subject: [PATCH] KTS-2787 "Search reports document indexer inconsistency and that the administrator must be contacted when the indexer has values but the document no longer exists in the repository" Fixed. --- search2/indexing/indexerCore.inc.php | 32 +++++++++++++++++++++++++++++--- search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php | 21 +++++++++++++++------ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/search2/indexing/indexerCore.inc.php b/search2/indexing/indexerCore.inc.php index ce037fe..e27772c 100755 --- a/search2/indexing/indexerCore.inc.php +++ b/search2/indexing/indexerCore.inc.php @@ -39,6 +39,9 @@ require_once('indexing/extractorCore.inc.php'); require_once(KT_DIR . '/plugins/ktcore/scheduler/schedulerUtil.php'); + +class IndexerInconsistencyException extends Exception {}; + class QueryResultItem { protected $document_id; @@ -92,7 +95,7 @@ class QueryResultItem case 'Title': return isset($this->title); case null: break; default: - throw new Exception("Unknown property '$property' to get on MatchResult"); + throw new Exception("Unknown property '$property' to get on QueryResultItem"); } return true; // should not be reached } @@ -137,7 +140,7 @@ class QueryResultItem $msg = 'The database did not have a record matching the result from the document indexer. This may occur if there is an inconsistency between the document indexer and the repository. The indexer needs to be repaired. Please consult the administrator guide as to how to repair your indexer.'; $default->log->error('QueryResultItem: ' . $msg); // TODO: repair process where we scan documents in index, and delete those for which there is nothing in the repository - throw new Exception(_kt($msg)); + throw new IndexerInconsistencyException(_kt($msg)); } // document_id, relevance, text, title @@ -274,7 +277,7 @@ class QueryResultItem case 'Title': $this->title = $value; break; case 'Text': $this->text = $value; break; default: - throw new Exception("Unknown property '$property' to set on MatchResult"); + throw new Exception("Unknown property '$property' to set on QueryResultItem"); } } } @@ -1144,6 +1147,29 @@ abstract class Indexer */ protected abstract function indexDocument($docId, $textFile, $title, $version); + + public function updateDocumentIndex($docId, $text) + { + $config = KTConfig::getSingleton(); + $tempPath = $config->get("urls/tmpDirectory"); + $tempFile = tempnam($tempPath,'ud_'); + + file_put_contents($tempFile, $text); + + $document = Document::get($docId); + $title = $document->getDescription(); + $version = $document->getVersion(); + + $result = $this->indexDocument($docId, $tempFile, $title, $version); + + if (file_exists($tempFile)) + { + unlink($tempFile); + } + + return $result; + } + /** * Index a discussion. The base class must override this function. * diff --git a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php index b1136a7..25b15d9 100755 --- a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php +++ b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php @@ -168,6 +168,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer */ public function query($query) { + global $default; $results = array(); $hits = $this->lucene->query($query); if (is_array($hits)) @@ -179,14 +180,22 @@ class JavaXMLRPCLuceneIndexer extends Indexer // avoid adding duplicates. If it is in already, it has higher priority. if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) { - $item = new QueryResultItem($document_id); - $item->Title = $hit->Title; - $item->Text = $hit->Content; - $item->Rank = $hit->Rank; + try + { + $item = new QueryResultItem($document_id); + $item->Title = $hit->Title; + $item->Text = $hit->Content; + $item->Rank = $hit->Rank; - if ($item->CanBeReadByUser) + if ($item->CanBeReadByUser) + { + $results[$document_id] = $item; + } + } + catch(IndexerInconsistencyException $ex) { - $results[$document_id] = $item; + $this->deleteDocument($document_id); + $default->log->info("Document Indexer inconsistency: $document_id has been found in document index but is not in the database."); } } } -- libgit2 0.21.4