diff --git a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php index 4e68882..dc23bf6 100755 --- a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php +++ b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php @@ -1,11 +1,153 @@ get('indexer/JavaLuceneURL', 'http://localhost:8875'); + $this->lucene = new XmlRpcLucene($javaServerUrl); + } + + /** + * Creates an index to be used. + * + */ + public static function createIndex() + { + // do nothing. The java lucene indexer will create the indexes if required + } + + /** + * Indexes a document based on a text file. + * + * @param int $docid + * @param string $textfile + * @return boolean + */ + protected function indexDocument($docid, $textfile, $title, $version) { - throw new Exception('TODO'); + try + { + return $this->lucene->addDocument($docid, $textfile, '', $title, $version); + } + catch(Exception $e) + { + return false; + } } + + /** + * Indexes the content and discussions on a document. + * + * @param int $docid + * @param string $textfile + * @return boolean + */ + protected function indexDocumentAndDiscussion($docid, $textfile, $title, $version) + { + try + { + $discussion = Indexer::getDiscussionText($docid); + return $this->lucene->addDocument($docid, $textfile, $discussion, $title, $version); + } + catch(Exception $e) + { + return false; + } + } + + /** + * Indexes a discussion on a document.. + * + * @param int $docid + * @return boolean + */ + protected function indexDiscussion($docid) + { + try + { + $discussion = Indexer::getDiscussionText($docid); + return $this->lucene->updateDiscussion($docid, $discussion); + } + catch(Exception $e) + { + return false; + } + + return true; + } + + /** + * Optimise the lucene index. + * This can be called periodically to optimise performance and size of the lucene index. + * + */ + public function optimise() + { + $this->lucene->optimize(); + } + + /** + * Removes a document from the index. + * + * @param int $docid + * @return array containing (content, discussion, title) + */ + public function deleteDocument($docid) + { + return $this->lucene->deleteDocument($docid); + } + + /** + * Enter description here... + * + * @param string $query + * @return array + */ + public function query($query) + { + $results = array(); + $hits = $this->lucene->query($query); + if (is_array($hits)) + { + foreach ($hits as $hit) + { + + + $document_id = $hit->DocumentID; + $content = $hit->Text; + $discussion = $hit->Title; //TODO: fix to be discussion. lucen server is not returning discussion text as well.. + $title = $hit->Title; + $score = $hit->Rank; + + // avoid adding duplicates. If it is in already, it has higher priority. + if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) + { + $results[$document_id] = new QueryResultItem($document_id, $score, $title, $content, $discussion); + } + } + } + else + { + $_SESSION['KTErrorMessage'][] = _kt('The XMLRPC Server did not respond correctly. Please notify the system administrator to investigate.'); + } + return $results; + } + } ?> \ No newline at end of file diff --git a/search2/indexing/indexers/PHPLuceneIndexer.inc.php b/search2/indexing/indexers/PHPLuceneIndexer.inc.php index 8d1c17e..60602e6 100755 --- a/search2/indexing/indexers/PHPLuceneIndexer.inc.php +++ b/search2/indexing/indexers/PHPLuceneIndexer.inc.php @@ -30,7 +30,7 @@ class PHPLuceneIndexer extends Indexer { $config =& KTConfig::getSingleton(); $indexPath = $config->get('indexer/luceneDirectory'); - $lucene = new Zend_Search_Lucene($indexPath, true); + new Zend_Search_Lucene($indexPath, true); } @@ -41,13 +41,14 @@ class PHPLuceneIndexer extends Indexer * @param string $content * @param string $discussion */ - private function addDocument($docid, $content, $discussion, $title='') + private function addDocument($docid, $content, $discussion, $title, $version) { $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('DocumentID', PHPLuceneIndexer::longToString($docid))); $doc->addField(Zend_Search_Lucene_Field::Text('Content', $content, 'UTF-8')); $doc->addField(Zend_Search_Lucene_Field::Text('Discussion', $discussion, 'UTF-8')); $doc->addField(Zend_Search_Lucene_Field::Text('Title', $title, 'UTF-8')); + $doc->addField(Zend_Search_Lucene_Field::Text('Version', $version, 'UTF-8')); $this->lucene->addDocument($doc); } @@ -58,7 +59,7 @@ class PHPLuceneIndexer extends Indexer * @param string $textfile * @return boolean */ - protected function indexDocument($docid, $textfile, $title='') + protected function indexDocument($docid, $textfile, $title, $version) { global $default; @@ -68,9 +69,9 @@ class PHPLuceneIndexer extends Indexer return false; } - list($content, $discussion) = $this->deleteDocument($docid); + list($content, $discussion, $title2, $version2) = $this->deleteDocument($docid); - $this->addDocument($docid, file_get_contents($textfile), $discussion, $title); + $this->addDocument($docid, file_get_contents($textfile), $discussion, $title, $version); return true; } @@ -82,7 +83,7 @@ class PHPLuceneIndexer extends Indexer * @param string $textfile * @return boolean */ - protected function indexDocumentAndDiscussion($docid, $textfile, $title='') + protected function indexDocumentAndDiscussion($docid, $textfile, $title, $version) { global $default; @@ -94,7 +95,7 @@ class PHPLuceneIndexer extends Indexer $this->deleteDocument($docid); - $this->addDocument($docid, file_get_contents($textfile), Indexer::getDiscussionText($docid), $title); + $this->addDocument($docid, file_get_contents($textfile), Indexer::getDiscussionText($docid), $title, $version); return true; } @@ -107,9 +108,9 @@ class PHPLuceneIndexer extends Indexer */ protected function indexDiscussion($docid) { - list($content, $discussion, $title) = $this->deleteDocument($docid); + list($content, $discussion, $title, $version) = $this->deleteDocument($docid); - $this->addDocument($docid, $content, Indexer::getDiscussionText($docid), $title); + $this->addDocument($docid, $content, Indexer::getDiscussionText($docid), $title, $version); return true; } @@ -142,11 +143,11 @@ class PHPLuceneIndexer extends Indexer $content = $hit->Content; $discussion = $hit->Discussion; $title = $hit->Title; - $title=''; + $version = $hit->Version; $this->lucene->delete($hit); } - return array($content, $discussion, $title); + return array($content, $discussion, $title, $version); } /**