From 1ba0311354a4e3cd7a2bb14a3c6b36676098e93b Mon Sep 17 00:00:00 2001 From: Conrad Vermeulen Date: Thu, 11 Oct 2007 18:03:58 +0000 Subject: [PATCH] KTS-673 "The search algorithm needs some work" Updated. --- search2/indexing/indexerCore.inc.php | 18 +++++++++++++++++- search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php | 48 ++++++++++++++++++++++++++++++++++++++++++------ search2/indexing/indexers/PHPLuceneIndexer.inc.php | 28 +++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/search2/indexing/indexerCore.inc.php b/search2/indexing/indexerCore.inc.php index 61ecf8a..675faf8 100755 --- a/search2/indexing/indexerCore.inc.php +++ b/search2/indexing/indexerCore.inc.php @@ -940,12 +940,28 @@ abstract class Indexer /** * Possibly we can optimise indexes. This method must be overriden. + * The new function must call the parent! * */ public function optimise() { - // do nothing + KTUtil::setSystemSetting('luceneOptimisationDate', time()); } + + /** + * Returns the name of the indexer. + * + * @return string + */ + public abstract function getDisplayName(); + + + /** + * Returns the number of non-deleted documents in the index. + * + * @return int + */ + public abstract function getDocumentsInIndex(); } ?> \ No newline at end of file diff --git a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php index f05f610..9a9b296 100755 --- a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php +++ b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php @@ -19,7 +19,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer parent::__construct(); $config =& KTConfig::getSingleton(); - $javaServerUrl = $config->get('indexer/JavaLuceneURL', 'http://localhost:8875'); + $javaServerUrl = $config->get('indexer/javaLuceneURL'); $this->lucene = new XmlRpcLucene($javaServerUrl); } @@ -99,6 +99,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer */ public function optimise() { + parent::optimise(); $this->lucene->optimize(); } @@ -149,22 +150,57 @@ class JavaXMLRPCLuceneIndexer extends Indexer return $results; } + /** + * Diagnose the indexer. e.g. Check that the indexing server is running. + * + */ public function diagnose() { - $config =& KTConfig::getSingleton(); + $config =& KTConfig::getSingleton(); + + $javaLuceneURL = $config->get('indexer/javaLuceneURL'); + + list($protocol, $host, $port) = explode(':', $javaLuceneURL); + if (empty($port)) $port == 8875; + if (substr($host, 0, 2) == '//') $host = substr($host, 2); - $ooHost = $config->get('openoffice/host', 'localhost'); - $ooPort = $config->get('openoffice/port', 8100); - $connection = @fsockopen($ooHost, $ooPort,$errno, $errstr, 2); + $connection = @fsockopen($host, $port, $errno, $errstr, 2); if (false === $connection) { - return _kt('Cannot connect to openoffice host'); + $indexer = $this->getDisplayName(); + return sprintf(_kt("Cannot connect to the %s on '%s'.\nPlease consult the Administrator Guide for more information on configuring the %s."), $indexer, $javaLuceneURL, $indexer); } fclose($connection); return null; + } + /** + * Returns the name of the indexer. + * + * @return string + */ + public function getDisplayName() + { + return _kt('Lucene Indexing Server'); + } + + + /** + * Returns the number of non-deleted documents in the index. + * + * @return int + */ + public function getDocumentsInIndex() + { + $stats = $this->lucene->getStatistics(); + if ($stats === false || !is_object($stats)) + { + return _kt('Not Available'); + } + return $stats->countDocuments; + } } ?> \ No newline at end of file diff --git a/search2/indexing/indexers/PHPLuceneIndexer.inc.php b/search2/indexing/indexers/PHPLuceneIndexer.inc.php index d1e2fa7..10879aa 100755 --- a/search2/indexing/indexers/PHPLuceneIndexer.inc.php +++ b/search2/indexing/indexers/PHPLuceneIndexer.inc.php @@ -131,10 +131,21 @@ class PHPLuceneIndexer extends Indexer */ public function optimise() { + parent::optimise(); $this->lucene->optimize(); } /** + * Returns the number of non-deleted documents in the index. + * + * @return int + */ + public function getDocumentsInIndex() + { + return $this->lucene->numDocs(); + } + + /** * Removes a document from the index. * * @param int $docid @@ -190,13 +201,28 @@ class PHPLuceneIndexer extends Indexer return $results; } + /** + * Diagnose the indexer. e.g. Check that the indexing server is running. + * + */ public function diagnose() { if ($this->lucene == null) { - return _kt("The lucene index has not been initialised correctly. Please review the documentation on how to setup the indexing."); + $indexer = $this->getDisplayName(); + return sprintf(_kt("The %s has not been initialised correctly. Please review the documentation on how to setup the indexing."),$indexer); } return null; } + + /** + * Returns the name of the indexer. + * + * @return string + */ + public function getDisplayName() + { + return _kt('Lucene PHP Indexer'); + } } ?> \ No newline at end of file -- libgit2 0.21.4