Commit 1445f9f41752194e79016cb6c12ed4e8f2d14eeb

Authored by conradverm
1 parent 89f6f2be

KTS-673

"The search algorithm needs some work"
Updated. added authentication between lucene server and kt

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7421 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/lib/XmlRpcLucene.inc.php
@@ -3,9 +3,28 @@ require_once('xmlrpc.inc'); @@ -3,9 +3,28 @@ require_once('xmlrpc.inc');
3 3
4 class XmlRpcLucene 4 class XmlRpcLucene
5 { 5 {
  6 + /**
  7 + * Reference to the xmlrpc client
  8 + *
  9 + * @var xmlrpc_client
  10 + */
6 var $client; 11 var $client;
7 12
8 /** 13 /**
  14 + * Identifier for the KT instance
  15 + *
  16 + * @var string
  17 + */
  18 + var $ktid;
  19 +
  20 + /**
  21 + * Identifier for the lucene server
  22 + *
  23 + * @var string
  24 + */
  25 + var $authToken;
  26 +
  27 + /**
9 * The constructoor for the lucene XMLRPC client. 28 * The constructoor for the lucene XMLRPC client.
10 * 29 *
11 * @param string $url 30 * @param string $url
@@ -16,6 +35,10 @@ class XmlRpcLucene @@ -16,6 +35,10 @@ class XmlRpcLucene
16 $this->client=new xmlrpc_client("$url/xmlrpc"); 35 $this->client=new xmlrpc_client("$url/xmlrpc");
17 $this->client->request_charset_encoding = 'UTF-8'; 36 $this->client->request_charset_encoding = 'UTF-8';
18 $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; 37 $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
  38 +
  39 + $config = KTConfig::getSingleton();
  40 + $this->authToken = $config->get('indexer/luceneAuthToken','');
  41 + $this->ktid = $config->get('indexer/luceneID','');
19 } 42 }
20 43
21 /** 44 /**
@@ -48,7 +71,11 @@ class XmlRpcLucene @@ -48,7 +71,11 @@ class XmlRpcLucene
48 */ 71 */
49 function optimise() 72 function optimise()
50 { 73 {
51 - $function=new xmlrpcmsg('indexer.optimise', array()); 74 + $function=new xmlrpcmsg('indexer.optimise',
  75 + array(
  76 + php_xmlrpc_encode((string) $this->ktid),
  77 + php_xmlrpc_encode((string) $this->authToken)
  78 + ));
52 79
53 $result=&$this->client->send($function); 80 $result=&$this->client->send($function);
54 if($result->faultCode()) 81 if($result->faultCode())
@@ -73,6 +100,8 @@ class XmlRpcLucene @@ -73,6 +100,8 @@ class XmlRpcLucene
73 { 100 {
74 $function=new xmlrpcmsg('indexer.addDocument', 101 $function=new xmlrpcmsg('indexer.addDocument',
75 array( 102 array(
  103 + php_xmlrpc_encode((string) $this->ktid),
  104 + php_xmlrpc_encode((string) $this->authToken),
76 php_xmlrpc_encode((int) $documentid), 105 php_xmlrpc_encode((int) $documentid),
77 php_xmlrpc_encode((string) $contentFile), 106 php_xmlrpc_encode((string) $contentFile),
78 php_xmlrpc_encode((string) $discussion), 107 php_xmlrpc_encode((string) $discussion),
@@ -97,7 +126,10 @@ class XmlRpcLucene @@ -97,7 +126,10 @@ class XmlRpcLucene
97 */ 126 */
98 function deleteDocument($documentid) 127 function deleteDocument($documentid)
99 { 128 {
100 - $function=new xmlrpcmsg('indexer.deleteDocument',array(php_xmlrpc_encode((int) $documentid))); 129 + $function=new xmlrpcmsg('indexer.deleteDocument',array(
  130 + php_xmlrpc_encode((string) $this->ktid),
  131 + php_xmlrpc_encode((string) $this->authToken),
  132 + php_xmlrpc_encode((int) $documentid)));
101 133
102 $result=&$this->client->send($function); 134 $result=&$this->client->send($function);
103 if($result->faultCode()) 135 if($result->faultCode())
@@ -116,7 +148,10 @@ class XmlRpcLucene @@ -116,7 +148,10 @@ class XmlRpcLucene
116 */ 148 */
117 function documentExists($documentid) 149 function documentExists($documentid)
118 { 150 {
119 - $function=new xmlrpcmsg('indexer.documentExists',array(php_xmlrpc_encode((int) $documentid))); 151 + $function=new xmlrpcmsg('indexer.documentExists',array(
  152 + php_xmlrpc_encode((string) $this->ktid),
  153 + php_xmlrpc_encode((string) $this->authToken),
  154 + php_xmlrpc_encode((int) $documentid)));
120 155
121 $result=&$this->client->send($function); 156 $result=&$this->client->send($function);
122 if($result->faultCode()) 157 if($result->faultCode())
@@ -134,7 +169,9 @@ class XmlRpcLucene @@ -134,7 +169,9 @@ class XmlRpcLucene
134 */ 169 */
135 function getStatistics() 170 function getStatistics()
136 { 171 {
137 - $function=new xmlrpcmsg('indexer.getStatistics',array()); 172 + $function=new xmlrpcmsg('indexer.getStatistics',array(
  173 + php_xmlrpc_encode((string) $this->ktid),
  174 + php_xmlrpc_encode((string) $this->authToken)));
138 175
139 176
140 $result=&$this->client->send($function); 177 $result=&$this->client->send($function);
@@ -159,7 +196,10 @@ class XmlRpcLucene @@ -159,7 +196,10 @@ class XmlRpcLucene
159 */ 196 */
160 function query($query) 197 function query($query)
161 { 198 {
162 - $function=new xmlrpcmsg('indexer.query',array(php_xmlrpc_encode((string) $query))); 199 + $function=new xmlrpcmsg('indexer.query',array(
  200 + php_xmlrpc_encode((string) $this->ktid),
  201 + php_xmlrpc_encode((string) $this->authToken),
  202 + php_xmlrpc_encode((string) $query)));
163 203
164 $result=&$this->client->send($function); 204 $result=&$this->client->send($function);
165 if($result->faultCode()) 205 if($result->faultCode())
@@ -182,8 +222,10 @@ class XmlRpcLucene @@ -182,8 +222,10 @@ class XmlRpcLucene
182 function updateDiscussion($docid, $discussion) 222 function updateDiscussion($docid, $discussion)
183 { 223 {
184 $function=new xmlrpcmsg('indexer.updateDiscussion',array( 224 $function=new xmlrpcmsg('indexer.updateDiscussion',array(
185 - php_xmlrpc_encode((int) $docid),  
186 - php_xmlrpc_encode((string) $discussion))); 225 + php_xmlrpc_encode((string) $this->ktid),
  226 + php_xmlrpc_encode((string) $this->authToken),
  227 + php_xmlrpc_encode((int) $docid),
  228 + php_xmlrpc_encode((string) $discussion)));
187 229
188 $result=&$this->client->send($function); 230 $result=&$this->client->send($function);
189 if($result->faultCode()) 231 if($result->faultCode())
@@ -196,7 +238,9 @@ class XmlRpcLucene @@ -196,7 +238,9 @@ class XmlRpcLucene
196 238
197 function shutdown() 239 function shutdown()
198 { 240 {
199 - $function=new xmlrpcmsg('indexer.shutdown',array()); 241 + $function=new xmlrpcmsg('indexer.shutdown',array(
  242 + php_xmlrpc_encode((string) $this->ktid),
  243 + php_xmlrpc_encode((string) $this->authToken)));
200 244
201 $result=&$this->client->send($function); 245 $result=&$this->client->send($function);
202 if($result->faultCode()) 246 if($result->faultCode())