ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  const LIKE_SEARCH = 0;
17  const INDEX_SEARCH = 1;
18  const LUCENE_SEARCH = 2;
19 
20  const OPERATOR_AND = 1;
21  const OPERATOR_OR = 2;
22 
23  protected static $instance = null;
24 
26  protected $fragmentSize = 30;
27  protected $fragmentCount = 3;
28  protected $numSubitems = 5;
29  protected $showRelevance = true;
30  protected $last_index_date = null;
31  protected $lucene_item_filter_enabled = false;
32  protected $lucene_item_filter = array();
33  protected $lucene_offline_filter = true;
34  protected $auto_complete_length = 10;
35 
36  protected $lucene_mime_filter_enabled = false;
37  protected $lucene_mime_filter = array();
38  protected $showSubRelevance = false;
39  protected $prefix_wildcard = false;
40 
41  protected $user_search = false;
42 
43  var $ilias = null;
44  var $max_hits = null;
45  var $index = null;
46 
47  function ilSearchSettings()
48  {
49  global $ilias;
50 
51  $this->ilias =& $ilias;
52  $this->__read();
53  }
54 
61  public static function getInstance()
62  {
63  if(self::$instance == null)
64  {
65  return self::$instance = new ilSearchSettings();
66  }
67  return self::$instance;
68  }
69 
75  public static function getLuceneItemFilterDefinitions()
76  {
77  return array(
78  'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
79  'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
80  'lms' => array('filter' => 'type:lm OR type:htlm OR type:sahs OR type:dbk','trans' => 'learning_resource'),
81  'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
82  'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
83  'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
84  'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
85  'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
86  'file' => array('filter' => 'type:file','trans' => 'objs_file'),
87  'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
88  'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki')
89  );
90  }
91 
92  public static function getLuceneMimeFilterDefinitions()
93  {
94  return array(
95  'pdf' => array('filter' => 'mimeType:pdf','trans' => 'search_mime_pdf'),
96  'word' => array('filter' => 'mimeType:word','trans' => 'search_mime_word'),
97  'excel' => array('filter' => 'mimeType:excel','trans' => 'search_mime_excel'),
98  'powerpoint' => array('filter' => 'mimeType:powerpoint','trans' => 'search_mime_powerpoint'),
99  'image' => array('filter' => 'mimeType:image','trans' => 'search_mime_image')
100  );
101  }
102 
109  {
110  if(!$this->isLuceneItemFilterEnabled())
111  {
112  return array();
113  }
114 
115  $filter = $this->getLuceneItemFilter();
116  $enabled = array();
117  foreach(self::getLuceneItemFilterDefinitions() as $obj => $def)
118  {
119  if(isset($filter[$obj]) and $filter[$obj])
120  {
121  $enabled[$obj] = $def;
122  }
123  }
124  return $enabled;
125  }
126 
127  // begin-patch mime_filter
129  {
130  if(!$this->isLuceneItemFilterEnabled())
131  {
132  return array();
133  }
134 
135  $filter = $this->getLuceneMimeFilter();
136  $enabled = array();
137  foreach(self::getLuceneMimeFilterDefinitions() as $mime => $def)
138  {
139  if(isset($filter[$mime]) and $filter[$mime])
140  {
141  $enabled[$mime] = $def;
142  }
143  }
144  return $enabled;
145  }
146 
147  public function enablePrefixWildcardQuery($a_stat)
148  {
149  $this->prefix_wildcard = $a_stat;
150  }
151 
153  {
154  return $this->prefix_wildcard;
155  }
156 
157  // end-patch mime_filter
158 
165  {
166  global $ilDB;
167 
168  static $seas_ref_id = 0;
169 
170  if($seas_ref_id)
171  {
172  return $seas_ref_id;
173  }
174  $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data ".
175  "WHERE tree.parent = ".$ilDB->quote(SYSTEM_FOLDER_ID,'integer')." ".
176  "AND object_data.type = 'seas' ".
177  "AND object_reference.ref_id = tree.child ".
178  "AND object_reference.obj_id = object_data.obj_id";
179 
180  $res = $ilDB->query($query);
181  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
182 
183  return $seas_ref_id = $row->ref_id;
184  }
185 
186  function enabledIndex()
187  {
188  global $ilDB;
189 
190  if($ilDB->getDBType() == 'oracle')
191  {
192  return false;
193  }
194  return $this->index ? true : false;
195  }
196  function enableIndex($a_status)
197  {
198  $this->index = $a_status;
199  }
200  function enabledLucene()
201  {
202  return $this->lucene ? true : false;
203  }
204  function enableLucene($a_status)
205  {
206  $this->lucene = $a_status ? true : false;
207  }
208 
209  function getMaxHits()
210  {
211  return $this->max_hits;
212  }
213  function setMaxHits($a_max_hits)
214  {
215  $this->max_hits = $a_max_hits;
216  }
217 
218  public function getDefaultOperator()
219  {
221  }
222 
223  public function setDefaultOperator($a_op)
224  {
225  $this->default_operator = $a_op;
226  }
227 
228  public function setFragmentSize($a_size)
229  {
230  $this->fragmentSize = $a_size;
231  }
232 
233  public function getFragmentSize()
234  {
235  return $this->fragmentSize;
236  }
237 
238  public function setFragmentCount($a_count)
239  {
240  $this->fragmentCount = $a_count;
241  }
242 
243  public function getHideAdvancedSearch()
244  {
245  return $this->hide_adv_search ? true : false;
246  }
247  public function setHideAdvancedSearch($a_status)
248  {
249  $this->hide_adv_search = $a_status;
250  }
251  public function getAutoCompleteLength()
252  {
254  }
256  {
257  $this->auto_complete_length = $auto_complete_length;
258  }
259 
260  public function getFragmentCount()
261  {
262  return $this->fragmentCount;
263  }
264 
265  public function setMaxSubitems($a_max)
266  {
267  $this->numSubitems = $a_max;
268  }
269 
270  public function getMaxSubitems()
271  {
272  return $this->numSubitems;
273  }
274 
275  public function isRelevanceVisible()
276  {
277  return $this->showRelevance;
278  }
279 
280  public function showRelevance($a_status)
281  {
282  $this->showRelevance = (bool) $a_status;
283  }
284 
285  public function getLastIndexTime()
286  {
287  return $this->last_index_date instanceof ilDateTime ?
288  $this->last_index_date :
289  new ilDateTime('2009-01-01 12:00:00',IL_CAL_DATETIME);
290  }
291 
292  public function enableLuceneItemFilter($a_status)
293  {
294  $this->lucene_item_filter_enabled = $a_status;
295  }
296 
297  public function isLuceneItemFilterEnabled()
298  {
300  }
301 
302  public function getLuceneItemFilter()
303  {
305  }
306 
307 
308  public function setLuceneItemFilter($a_filter)
309  {
310  $this->lucene_item_filter = $a_filter;
311  }
312 
313  public function enableLuceneOfflineFilter($a_stat)
314  {
315  $this->lucene_offline_filter = $a_stat;
316  }
317 
319  {
321  }
322 
323  public function showSubRelevance($a_stat)
324  {
325  $this->showSubRelevance = $a_stat;
326  }
327 
328  public function isSubRelevanceVisible()
329  {
331  }
332 
333 
334  public function setLuceneMimeFilter($a_filter)
335  {
336  $this->lucene_mime_filter = $a_filter;
337  }
338 
339  public function getLuceneMimeFilter()
340  {
342  }
343 
347  public function isLuceneMimeFilterEnabled()
348  {
350  }
351 
356  public function enableLuceneMimeFilter($a_stat)
357  {
358  $this->lucene_mime_filter_enabled = $a_stat;
359  }
360 
361 
365  public function setLastIndexTime($time)
366  {
367  $this->last_index_date = $time;
368  }
369 
374  public function isLuceneUserSearchEnabled()
375  {
376  return $this->user_search;
377  }
378 
383  public function enableLuceneUserSearch($a_status)
384  {
385  $this->user_search = $a_status;
386  }
387 
388  function update()
389  {
390  global $ilSetting;
391 
392  $this->ilias->setSetting('search_max_hits',$this->getMaxHits());
393  $this->ilias->setSetting('search_index',(int) $this->enabledIndex());
394  $this->ilias->setSetting('search_lucene',(int) $this->enabledLucene());
395 
396  $this->ilias->setSetting('lucene_default_operator',$this->getDefaultOperator());
397  $this->ilias->setSetting('lucene_fragment_size',$this->getFragmentSize());
398  $this->ilias->setSetting('lucene_fragment_count',$this->getFragmentCount());
399  $this->ilias->setSetting('lucene_max_subitems',$this->getMaxSubitems());
400  $this->ilias->setSetting('lucene_show_relevance',$this->isRelevanceVisible());
401  $this->ilias->setSetting('lucene_last_index_time',$this->getLastIndexTime()->get(IL_CAL_UNIX));
402  $this->ilias->setSetting('hide_adv_search',(int) $this->getHideAdvancedSearch());
403  $this->ilias->setSetting('auto_complete_length',(int) $this->getAutoCompleteLength());
404  $this->ilias->setSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled());
405  $this->ilias->setSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
406  $this->ilias->setSetting('lucene_offline_filter',(int) $this->isLuceneOfflineFilterEnabled());
407  $this->ilias->setSetting('lucene_mime_filter',serialize($this->getLuceneMimeFilter()));
408  $this->ilias->setSetting('lucene_sub_relevance',$this->isSubRelevanceVisible());
409  $ilSetting->set('lucene_mime_filter_enabled',$this->isLuceneMimeFilterEnabled());
410  $this->ilias->setSetting('lucene_prefix_wildcard',$this->isPrefixWildcardQueryEnabled());
411  $ilSetting->set('lucene_user_search',$this->isLuceneUserSearchEnabled());
412 
413  return true;
414  }
415 
416  // PRIVATE
417  function __read()
418  {
419  global $ilSetting;
420 
421  $this->setMaxHits($this->ilias->getSetting('search_max_hits',10));
422  $this->enableIndex($this->ilias->getSetting('search_index',0));
423  $this->enableLucene($this->ilias->getSetting('search_lucene',0));
424 
425  $this->setDefaultOperator($this->ilias->getSetting('lucene_default_operator',self::OPERATOR_AND));
426  $this->setFragmentSize($this->ilias->getSetting('lucene_fragment_size',50));
427  $this->setFragmentCount($this->ilias->getSetting('lucene_fragment_count',3));
428  $this->setMaxSubitems($this->ilias->getSetting('lucene_max_subitems',5));
429  $this->showRelevance($this->ilias->getSetting('lucene_show_relevance',true));
430 
431  if($time = $this->ilias->getSetting('lucene_last_index_time',false))
432  {
433  $this->setLastIndexTime(new ilDateTime($time,IL_CAL_UNIX));
434  }
435  else
436  {
437  $this->setLastIndexTime(null);
438  }
439 
440  $this->setHideAdvancedSearch($this->ilias->getSetting('hide_adv_search',0));
441  $this->setAutoCompleteLength($this->ilias->getSetting('auto_complete_length',$this->getAutoCompleteLength()));
442 
443  $this->enableLuceneItemFilter($this->ilias->getSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled()));
444 
445  $filter = $this->ilias->getSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
446  $this->setLuceneItemFilter(unserialize($filter));
447  $this->enableLuceneOfflineFilter($this->ilias->getSetting('lucene_offline_filter'), $this->isLuceneOfflineFilterEnabled());
448 
449  $this->enableLuceneMimeFilter($ilSetting->get('lucene_mime_filter_enabled',$this->lucene_item_filter_enabled));
450  $filter = $this->ilias->getSetting('lucene_mime_filter',serialize($this->getLuceneMimeFilter()));
451  $this->setLuceneMimeFilter(unserialize($filter));
452  $this->showSubRelevance($this->ilias->getSetting('lucene_sub_relevance',$this->showSubRelevance));
453  $this->enablePrefixWildcardQuery($this->ilias->getSetting('lucene_prefix_wildcard',$this->prefix_wildcard));
454  $this->enableLuceneUserSearch($ilSetting->get('lucene_user_search',$this->user_search));
455 
456  }
457 }
458 ?>