Commit 1e5d07d096328d4f3dbcf0e04c62e38c5890ecc1
1 parent
2fe27c1e
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@7294 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
213 additions
and
0 deletions
search2/indexing/lib/XmlRpcLucene.inc.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once('xmlrpc.inc'); | ||
| 3 | + | ||
| 4 | +class XmlRpcLucene | ||
| 5 | +{ | ||
| 6 | + var $client; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * The constructoor for the lucene XMLRPC client. | ||
| 10 | + * | ||
| 11 | + * @param string $url | ||
| 12 | + * @param int $port | ||
| 13 | + */ | ||
| 14 | + public function __construct($url) | ||
| 15 | + { | ||
| 16 | + $this->client=new xmlrpc_client("$url/xmlrpc"); | ||
| 17 | + $this->client->request_charset_encoding = 'UTF-8'; | ||
| 18 | + $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * Set a level for debugging. | ||
| 23 | + * | ||
| 24 | + * @param int $level | ||
| 25 | + */ | ||
| 26 | + function debug($level) | ||
| 27 | + { | ||
| 28 | + $this->client->setDebug($level); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Logs errors to the log file | ||
| 33 | + * | ||
| 34 | + * @param xmlrpcresult $result | ||
| 35 | + * @param string $function | ||
| 36 | + */ | ||
| 37 | + function error($result, $function) | ||
| 38 | + { | ||
| 39 | + global $default; | ||
| 40 | + $default->log->error('XMLRPC Lucene - ' . $function . ' - Code: ' . htmlspecialchars($result->faultCode())); | ||
| 41 | + $default->log->error('XMLRPC Lucene - ' . $function . ' - Reason: ' . htmlspecialchars($result->faultString())); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Optimise the lucene index. | ||
| 46 | + * | ||
| 47 | + * @return boolean | ||
| 48 | + */ | ||
| 49 | + function optimise() | ||
| 50 | + { | ||
| 51 | + $function=new xmlrpcmsg('indexer.optimise', array()); | ||
| 52 | + | ||
| 53 | + $result=&$this->client->send($function); | ||
| 54 | + if($result->faultCode()) | ||
| 55 | + { | ||
| 56 | + $this->error($result, 'optimise'); | ||
| 57 | + return false; | ||
| 58 | + } | ||
| 59 | + return php_xmlrpc_decode($result->value()) == 0; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Add a document to lucene | ||
| 64 | + * | ||
| 65 | + * @param int $documentid | ||
| 66 | + * @param string $contentFile | ||
| 67 | + * @param string $discussion | ||
| 68 | + * @param string $title | ||
| 69 | + * @param string $version | ||
| 70 | + * @return boolean | ||
| 71 | + */ | ||
| 72 | + function addDocument($documentid, $contentFile, $discussion, $title, $version) | ||
| 73 | + { | ||
| 74 | + $function=new xmlrpcmsg('indexer.addDocument', | ||
| 75 | + array( | ||
| 76 | + php_xmlrpc_encode((int) $documentid), | ||
| 77 | + php_xmlrpc_encode((string) $contentFile), | ||
| 78 | + php_xmlrpc_encode((string) $discussion), | ||
| 79 | + php_xmlrpc_encode((string) $title), | ||
| 80 | + php_xmlrpc_encode((string) $version) | ||
| 81 | + )); | ||
| 82 | + | ||
| 83 | + $result=&$this->client->send($function); | ||
| 84 | + if($result->faultCode()) | ||
| 85 | + { | ||
| 86 | + $this->error($result, 'addDocument'); | ||
| 87 | + return false; | ||
| 88 | + } | ||
| 89 | + return php_xmlrpc_decode($result->value()) == 0; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Remove the document from the index. | ||
| 94 | + * | ||
| 95 | + * @param int $documentid | ||
| 96 | + * @return boolean | ||
| 97 | + */ | ||
| 98 | + function deleteDocument($documentid) | ||
| 99 | + { | ||
| 100 | + $function=new xmlrpcmsg('indexer.deleteDocument',array(php_xmlrpc_encode((int) $documentid))); | ||
| 101 | + | ||
| 102 | + $result=&$this->client->send($function); | ||
| 103 | + if($result->faultCode()) | ||
| 104 | + { | ||
| 105 | + $this->error($result, 'deleteDocument'); | ||
| 106 | + return false; | ||
| 107 | + } | ||
| 108 | + return php_xmlrpc_decode($result->value()) == 0; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Does the document exist? | ||
| 113 | + * | ||
| 114 | + * @param int $documentid | ||
| 115 | + * @return boolean | ||
| 116 | + */ | ||
| 117 | + function documentExists($documentid) | ||
| 118 | + { | ||
| 119 | + $function=new xmlrpcmsg('indexer.documentExists',array(php_xmlrpc_encode((int) $documentid))); | ||
| 120 | + | ||
| 121 | + $result=&$this->client->send($function); | ||
| 122 | + if($result->faultCode()) | ||
| 123 | + { | ||
| 124 | + $this->error($result, 'deleteDocument'); | ||
| 125 | + return false; | ||
| 126 | + } | ||
| 127 | + return php_xmlrpc_decode($result->value()); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Get statistics from the indexer | ||
| 132 | + * | ||
| 133 | + * @return array | ||
| 134 | + */ | ||
| 135 | + function getStatistics() | ||
| 136 | + { | ||
| 137 | + $function=new xmlrpcmsg('indexer.getStatistics',array()); | ||
| 138 | + | ||
| 139 | + | ||
| 140 | + $result=&$this->client->send($function); | ||
| 141 | + if($result->faultCode()) | ||
| 142 | + { | ||
| 143 | + $this->error($result, 'getStatistics'); | ||
| 144 | + return false; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + $result = php_xmlrpc_decode($result->value()); | ||
| 148 | + | ||
| 149 | + //print $result; | ||
| 150 | + | ||
| 151 | + return json_decode($result); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * Run a query on the lucene index | ||
| 156 | + * | ||
| 157 | + * @param string $query | ||
| 158 | + * @return boolean | ||
| 159 | + */ | ||
| 160 | + function query($query) | ||
| 161 | + { | ||
| 162 | + $function=new xmlrpcmsg('indexer.query',array(php_xmlrpc_encode((string) $query))); | ||
| 163 | + | ||
| 164 | + $result=&$this->client->send($function); | ||
| 165 | + if($result->faultCode()) | ||
| 166 | + { | ||
| 167 | + $this->error($result, 'query'); | ||
| 168 | + return false; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + $result = php_xmlrpc_decode($result->value()); | ||
| 172 | + return json_decode($result); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * Updates the discussion text on a given document. | ||
| 177 | + * | ||
| 178 | + * @param int $docid | ||
| 179 | + * @param string $discussion | ||
| 180 | + * @return boolean | ||
| 181 | + */ | ||
| 182 | + function updateDiscussion($docid, $discussion) | ||
| 183 | + { | ||
| 184 | + $function=new xmlrpcmsg('indexer.updateDiscussion',array( | ||
| 185 | + php_xmlrpc_encode((int) $docid), | ||
| 186 | + php_xmlrpc_encode((string) $discussion))); | ||
| 187 | + | ||
| 188 | + $result=&$this->client->send($function); | ||
| 189 | + if($result->faultCode()) | ||
| 190 | + { | ||
| 191 | + $this->error($result, 'updateDiscussion'); | ||
| 192 | + return false; | ||
| 193 | + } | ||
| 194 | + return php_xmlrpc_decode($result->value()) == 0; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + function shutdown() | ||
| 198 | + { | ||
| 199 | + $function=new xmlrpcmsg('indexer.shutdown',array()); | ||
| 200 | + | ||
| 201 | + $result=&$this->client->send($function); | ||
| 202 | + if($result->faultCode()) | ||
| 203 | + { | ||
| 204 | + $this->error($result, 'shutdown'); | ||
| 205 | + return false; | ||
| 206 | + } | ||
| 207 | + return true; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +?> | ||
| 0 | \ No newline at end of file | 214 | \ No newline at end of file |