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