Commit 7c5f078854757674bc420464f8e6b39b629a2761

Authored by conradverm
1 parent 44a0ea13

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.

Committed By: Conrad Vermeulen
Reviewed By: Jalaloedien Abrahams

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7832 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/indexerCore.inc.php
... ... @@ -39,6 +39,9 @@
39 39 require_once('indexing/extractorCore.inc.php');
40 40 require_once(KT_DIR . '/plugins/ktcore/scheduler/schedulerUtil.php');
41 41  
  42 +
  43 +class IndexerInconsistencyException extends Exception {};
  44 +
42 45 class QueryResultItem
43 46 {
44 47 protected $document_id;
... ... @@ -92,7 +95,7 @@ class QueryResultItem
92 95 case 'Title': return isset($this->title);
93 96 case null: break;
94 97 default:
95   - throw new Exception("Unknown property '$property' to get on MatchResult");
  98 + throw new Exception("Unknown property '$property' to get on QueryResultItem");
96 99 }
97 100 return true; // should not be reached
98 101 }
... ... @@ -137,7 +140,7 @@ class QueryResultItem
137 140 $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.';
138 141 $default->log->error('QueryResultItem: ' . $msg);
139 142 // TODO: repair process where we scan documents in index, and delete those for which there is nothing in the repository
140   - throw new Exception(_kt($msg));
  143 + throw new IndexerInconsistencyException(_kt($msg));
141 144 }
142 145  
143 146 // document_id, relevance, text, title
... ... @@ -274,7 +277,7 @@ class QueryResultItem
274 277 case 'Title': $this->title = $value; break;
275 278 case 'Text': $this->text = $value; break;
276 279 default:
277   - throw new Exception("Unknown property '$property' to set on MatchResult");
  280 + throw new Exception("Unknown property '$property' to set on QueryResultItem");
278 281 }
279 282 }
280 283 }
... ... @@ -1144,6 +1147,29 @@ abstract class Indexer
1144 1147 */
1145 1148 protected abstract function indexDocument($docId, $textFile, $title, $version);
1146 1149  
  1150 +
  1151 + public function updateDocumentIndex($docId, $text)
  1152 + {
  1153 + $config = KTConfig::getSingleton();
  1154 + $tempPath = $config->get("urls/tmpDirectory");
  1155 + $tempFile = tempnam($tempPath,'ud_');
  1156 +
  1157 + file_put_contents($tempFile, $text);
  1158 +
  1159 + $document = Document::get($docId);
  1160 + $title = $document->getDescription();
  1161 + $version = $document->getVersion();
  1162 +
  1163 + $result = $this->indexDocument($docId, $tempFile, $title, $version);
  1164 +
  1165 + if (file_exists($tempFile))
  1166 + {
  1167 + unlink($tempFile);
  1168 + }
  1169 +
  1170 + return $result;
  1171 + }
  1172 +
1147 1173 /**
1148 1174 * Index a discussion. The base class must override this function.
1149 1175 *
... ...
search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php
... ... @@ -168,6 +168,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer
168 168 */
169 169 public function query($query)
170 170 {
  171 + global $default;
171 172 $results = array();
172 173 $hits = $this->lucene->query($query);
173 174 if (is_array($hits))
... ... @@ -179,14 +180,22 @@ class JavaXMLRPCLuceneIndexer extends Indexer
179 180 // avoid adding duplicates. If it is in already, it has higher priority.
180 181 if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score)
181 182 {
182   - $item = new QueryResultItem($document_id);
183   - $item->Title = $hit->Title;
184   - $item->Text = $hit->Content;
185   - $item->Rank = $hit->Rank;
  183 + try
  184 + {
  185 + $item = new QueryResultItem($document_id);
  186 + $item->Title = $hit->Title;
  187 + $item->Text = $hit->Content;
  188 + $item->Rank = $hit->Rank;
186 189  
187   - if ($item->CanBeReadByUser)
  190 + if ($item->CanBeReadByUser)
  191 + {
  192 + $results[$document_id] = $item;
  193 + }
  194 + }
  195 + catch(IndexerInconsistencyException $ex)
188 196 {
189   - $results[$document_id] = $item;
  197 + $this->deleteDocument($document_id);
  198 + $default->log->info("Document Indexer inconsistency: $document_id has been found in document index but is not in the database.");
190 199 }
191 200 }
192 201 }
... ...