ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLuceneRPCAdapter.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
33 include_once 'Services/WebServices/RPC/classes/class.ilRPCServerAdapter.php';
34 
36 {
37  var $mode = '';
38  var $files = array();
39  var $query_str = '';
41  var $filter = '';
42 
43 
44  function ilLuceneRPCAdapter()
45  {
47  }
48 
49  function setMode($a_mode)
50  {
51  $this->mode = $a_mode;
52  }
53  function getMode()
54  {
55  return $this->mode;
56  }
57  function setFiles(&$files)
58  {
59  $this->files =& $files;
60  }
61  function &getFiles()
62  {
63  return $this->files ? $this->files : array();
64  }
65  function setHTLMs(&$htlms)
66  {
67  $this->htlms = $htlms;
68  }
69  function &getHTLMs()
70  {
71  return $this->htlms;
72  }
73 
74  function setQueryString($a_str)
75  {
76  $this->query_str = $a_str;
77  }
78  function getQueryString()
79  {
80  return $this->query_str;
81  }
82  function setPageNumber($a_number)
83  {
84  $this->page_number = $a_number;
85  }
86  function getPageNumber()
87  {
88  return $this->page_number;
89  }
90 
91  function setSearchFilter($a_filter)
92  {
93  $this->filter = $a_filter;
94  }
95  function getSearchFilter()
96  {
97  return $this->filter ? $this->filter : array();
98  }
99 
105  function __getClientId()
106  {
107  global $ilias;
108 
109  // TODO: handle problem if nic_key isn't set
110  return $ilias->getSetting('nic_key').'_'.CLIENT_ID;
111  }
112 
113 
114 
115  function send()
116  {
117  $this->__initClient();
118  switch($this->getMode())
119  {
120  case 'ping':
121  $this->__preparePingParams();
122  break;
123 
124  case 'file':
125  $this->__prepareIndexFileParams();
126  break;
127 
128  case 'query':
129  $this->__prepareQueryParams();
130  break;
131 
132  case 'htlm':
133  $this->__prepareIndexHTLMParams();
134  break;
135 
136  case 'flush':
137  $this->__prepareFlushIndex();
138  break;
139 
140  // BEGIN PATCH Lucene search
141  case 'search':
142  $this->__prepareSearchParams();
143  break;
144 
145  case 'highlight':
146  $this->__prepareHighlightParams();
147  break;
148 
149  case 'refreshSettings':
151  break;
152  // END PATCH Lucene Search
153 
154  default:
155  $this->log->write('ilLuceneRPCHandler(): No valid mode given');
156  return false;
157 
158  }
159  return parent::send();
160  }
161  // PRIVATE
163  {
164  $this->setResponseTimeout(5);
165  $filter = array();
166  foreach($this->getSearchFilter() as $obj_type)
167  {
168  $filter[] = new XML_RPC_Value($obj_type,'string');
169  }
170  $this->__initMessage('Searcher.ilSearch',array(new XML_RPC_Value($this->__getClientId(),"string"),
171  new XML_RPC_Value($this->getQueryString(),"string"),
172  new XML_RPC_Value($filter,'array')));
173 
174  return true;
175  }
176 
178  {
179  $this->setResponseTimeout(5);
180  $this->__initMessage('Searcher.ilPing',array(new XML_RPC_Value($this->__getClientId(),"string")));
181 
182  return true;
183  }
184 
186  {
187  $this->setResponseTimeout(5);
188  foreach($this->getFiles() as $obj_id => $fname)
189  {
190  $struct[$obj_id] = new XML_RPC_Value($fname,"string");
191  }
192  $params = array(new XML_RPC_Value($this->__getClientId(),"string"),
193  new XML_RPC_Value($struct,"struct"));
194 
195  $this->__initMessage('Indexer.ilFileIndexer',$params);
196 
197  return true;
198  }
199 
201  {
202  $this->setResponseTimeout(5);
203  foreach($this->getHTLMs() as $obj_id => $fname)
204  {
205  $struct[$obj_id] = new XML_RPC_Value($fname,"string");
206  }
207 
208  $this->__initMessage('Indexer.ilHTLMIndexer',array(new XML_RPC_Value($this->__getClientId(),"string"),
209  new XML_RPC_Value($struct,"struct")));
210 
211  return true;
212  }
214  {
215  $this->setResponseTimeout(5);
216  $this->__initMessage('Indexer.ilClearIndex',array(new XML_RPC_Value($this->__getClientId(),"string")));
217 
218  return true;
219  }
220 
221  // BEGIN PATCH Lucene search
225  protected function __prepareSearchParams()
226  {
227  $this->setResponseTimeout(5);
228  $this->__initMessage('RPCSearchHandler.search',array(
229  new XML_RPC_Value($this->getClientKey(),'string'),
230  new XML_RPC_Value($this->getQueryString(),'string'),
231  new XML_RPC_Value($this->getPageNumber(),'int')));
232 
233  return true;
234  }
235 
239  protected function __prepareHighlightParams()
240  {
241  $this->setResponseTimeout(5);
242 
243  $objIds = array();
244  foreach($this->getResultIds() as $obj_id)
245  {
246  $objIds[] = new XML_RPC_Value($obj_id,'int');
247  }
248 
249  $this->__initMessage('RPCSearchHandler.highlight',array(
250  new XML_RPC_Value($this->getClientKey(),'string'),
251  new XML_RPC_VAlue($objIds,'array'),
252  new XML_RPC_Value($this->getQueryString(),'string')));
253 
254  return true;
255  }
256 
257  protected function __prepareRefreshSettingsParams()
258  {
259  $this->setResponseTimeout(5);
260 
261  $this->__initMessage('RPCAdministration.refreshSettings',array(
262  new XML_RPC_Value($this->getClientKey(),'string')));
263  return true;
264  }
265 
271  public function setResultIds($a_ids)
272  {
273  $this->result_ids = $a_ids;
274  }
275 
280  public function getResultIds()
281  {
282  return $this->result_ids ? $this->result_ids : array();
283  }
284 
285 
290  protected function getClientKey()
291  {
292  global $ilSetting;
293 
294  return CLIENT_ID.'_'.$ilSetting->get('inst_id',0);
295  }
296  // END PATCH Lucene Search
297 }
298 ?>