Commit 1ba0311354a4e3cd7a2bb14a3c6b36676098e93b

Authored by Conrad Vermeulen
1 parent b504afdc

KTS-673

"The search algorithm needs some work"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7338 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/indexerCore.inc.php
@@ -940,12 +940,28 @@ abstract class Indexer @@ -940,12 +940,28 @@ abstract class Indexer
940 940
941 /** 941 /**
942 * Possibly we can optimise indexes. This method must be overriden. 942 * Possibly we can optimise indexes. This method must be overriden.
  943 + * The new function must call the parent!
943 * 944 *
944 */ 945 */
945 public function optimise() 946 public function optimise()
946 { 947 {
947 - // do nothing 948 + KTUtil::setSystemSetting('luceneOptimisationDate', time());
948 } 949 }
  950 +
  951 + /**
  952 + * Returns the name of the indexer.
  953 + *
  954 + * @return string
  955 + */
  956 + public abstract function getDisplayName();
  957 +
  958 +
  959 + /**
  960 + * Returns the number of non-deleted documents in the index.
  961 + *
  962 + * @return int
  963 + */
  964 + public abstract function getDocumentsInIndex();
949 } 965 }
950 966
951 ?> 967 ?>
952 \ No newline at end of file 968 \ No newline at end of file
search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php
@@ -19,7 +19,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer @@ -19,7 +19,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer
19 parent::__construct(); 19 parent::__construct();
20 20
21 $config =& KTConfig::getSingleton(); 21 $config =& KTConfig::getSingleton();
22 - $javaServerUrl = $config->get('indexer/JavaLuceneURL', 'http://localhost:8875'); 22 + $javaServerUrl = $config->get('indexer/javaLuceneURL');
23 $this->lucene = new XmlRpcLucene($javaServerUrl); 23 $this->lucene = new XmlRpcLucene($javaServerUrl);
24 } 24 }
25 25
@@ -99,6 +99,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer @@ -99,6 +99,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer
99 */ 99 */
100 public function optimise() 100 public function optimise()
101 { 101 {
  102 + parent::optimise();
102 $this->lucene->optimize(); 103 $this->lucene->optimize();
103 } 104 }
104 105
@@ -149,22 +150,57 @@ class JavaXMLRPCLuceneIndexer extends Indexer @@ -149,22 +150,57 @@ class JavaXMLRPCLuceneIndexer extends Indexer
149 return $results; 150 return $results;
150 } 151 }
151 152
  153 + /**
  154 + * Diagnose the indexer. e.g. Check that the indexing server is running.
  155 + *
  156 + */
152 public function diagnose() 157 public function diagnose()
153 { 158 {
154 - $config =& KTConfig::getSingleton(); 159 + $config =& KTConfig::getSingleton();
  160 +
  161 + $javaLuceneURL = $config->get('indexer/javaLuceneURL');
  162 +
  163 + list($protocol, $host, $port) = explode(':', $javaLuceneURL);
  164 + if (empty($port)) $port == 8875;
  165 + if (substr($host, 0, 2) == '//') $host = substr($host, 2);
155 166
156 - $ooHost = $config->get('openoffice/host', 'localhost');  
157 - $ooPort = $config->get('openoffice/port', 8100);  
158 - $connection = @fsockopen($ooHost, $ooPort,$errno, $errstr, 2); 167 + $connection = @fsockopen($host, $port, $errno, $errstr, 2);
159 if (false === $connection) 168 if (false === $connection)
160 { 169 {
161 - return _kt('Cannot connect to openoffice host'); 170 + $indexer = $this->getDisplayName();
  171 + 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);
162 } 172 }
163 fclose($connection); 173 fclose($connection);
164 174
165 return null; 175 return null;
  176 +
166 } 177 }
167 178
  179 + /**
  180 + * Returns the name of the indexer.
  181 + *
  182 + * @return string
  183 + */
  184 + public function getDisplayName()
  185 + {
  186 + return _kt('Lucene Indexing Server');
  187 + }
  188 +
  189 +
  190 + /**
  191 + * Returns the number of non-deleted documents in the index.
  192 + *
  193 + * @return int
  194 + */
  195 + public function getDocumentsInIndex()
  196 + {
  197 + $stats = $this->lucene->getStatistics();
  198 + if ($stats === false || !is_object($stats))
  199 + {
  200 + return _kt('Not Available');
  201 + }
  202 + return $stats->countDocuments;
  203 + }
168 204
169 } 205 }
170 ?> 206 ?>
171 \ No newline at end of file 207 \ No newline at end of file
search2/indexing/indexers/PHPLuceneIndexer.inc.php
@@ -131,10 +131,21 @@ class PHPLuceneIndexer extends Indexer @@ -131,10 +131,21 @@ class PHPLuceneIndexer extends Indexer
131 */ 131 */
132 public function optimise() 132 public function optimise()
133 { 133 {
  134 + parent::optimise();
134 $this->lucene->optimize(); 135 $this->lucene->optimize();
135 } 136 }
136 137
137 /** 138 /**
  139 + * Returns the number of non-deleted documents in the index.
  140 + *
  141 + * @return int
  142 + */
  143 + public function getDocumentsInIndex()
  144 + {
  145 + return $this->lucene->numDocs();
  146 + }
  147 +
  148 + /**
138 * Removes a document from the index. 149 * Removes a document from the index.
139 * 150 *
140 * @param int $docid 151 * @param int $docid
@@ -190,13 +201,28 @@ class PHPLuceneIndexer extends Indexer @@ -190,13 +201,28 @@ class PHPLuceneIndexer extends Indexer
190 return $results; 201 return $results;
191 } 202 }
192 203
  204 + /**
  205 + * Diagnose the indexer. e.g. Check that the indexing server is running.
  206 + *
  207 + */
193 public function diagnose() 208 public function diagnose()
194 { 209 {
195 if ($this->lucene == null) 210 if ($this->lucene == null)
196 { 211 {
197 - return _kt("The lucene index has not been initialised correctly. Please review the documentation on how to setup the indexing."); 212 + $indexer = $this->getDisplayName();
  213 + return sprintf(_kt("The %s has not been initialised correctly. Please review the documentation on how to setup the indexing."),$indexer);
198 } 214 }
199 return null; 215 return null;
200 } 216 }
  217 +
  218 + /**
  219 + * Returns the name of the indexer.
  220 + *
  221 + * @return string
  222 + */
  223 + public function getDisplayName()
  224 + {
  225 + return _kt('Lucene PHP Indexer');
  226 + }
201 } 227 }
202 ?> 228 ?>
203 \ No newline at end of file 229 \ No newline at end of file