ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
25  protected $default_operator = self::OPERATOR_AND;
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  protected $show_inactiv_user = true;
36  protected $show_limited_user = true;
37 
38  protected $lucene_mime_filter_enabled = false;
39  protected $lucene_mime_filter = array();
40  protected $showSubRelevance = false;
41  protected $prefix_wildcard = false;
42 
43  protected $user_search = false;
44 
45  protected $date_filter = FALSE;
46 
47  var $ilias = null;
48  var $max_hits = null;
49  var $index = null;
50 
51  function __construct()
52  {
53  global $ilias;
54 
55  $this->ilias = $ilias;
56  $this->__read();
57  }
58 
65  public static function getInstance()
66  {
67  if(self::$instance == null)
68  {
69  return self::$instance = new ilSearchSettings();
70  }
71  return self::$instance;
72  }
73 
79  public static function getLuceneItemFilterDefinitions()
80  {
81  return array(
82  'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
83  'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
84  'lms' => array('filter' => 'type:lm OR type:htlm OR type:sahs OR type:dbk','trans' => 'learning_resource'),
85  'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
86  'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
87  'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
88  'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
89  'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
90  'file' => array('filter' => 'type:file','trans' => 'objs_file'),
91  'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
92  'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki')
93  );
94  }
95 
96  public static function getLuceneMimeFilterDefinitions()
97  {
98  return array(
99  'pdf' => array('filter' => 'mimeType:pdf','trans' => 'search_mime_pdf'),
100  'word' => array('filter' => 'mimeType:word','trans' => 'search_mime_word'),
101  'excel' => array('filter' => 'mimeType:excel','trans' => 'search_mime_excel'),
102  'powerpoint' => array('filter' => 'mimeType:powerpoint','trans' => 'search_mime_powerpoint'),
103  'image' => array('filter' => 'mimeType:image','trans' => 'search_mime_image')
104  );
105  }
106 
113  {
114  if(!$this->isLuceneItemFilterEnabled())
115  {
116  return array();
117  }
118 
119  $filter = $this->getLuceneItemFilter();
120  $enabled = array();
121  foreach(self::getLuceneItemFilterDefinitions() as $obj => $def)
122  {
123  if(isset($filter[$obj]) and $filter[$obj])
124  {
125  $enabled[$obj] = $def;
126  }
127  }
128  return $enabled;
129  }
130 
131  // begin-patch mime_filter
133  {
134  if(!$this->isLuceneItemFilterEnabled())
135  {
136  return array();
137  }
138 
139  $filter = $this->getLuceneMimeFilter();
140  $enabled = array();
141  foreach(self::getLuceneMimeFilterDefinitions() as $mime => $def)
142  {
143  if(isset($filter[$mime]) and $filter[$mime])
144  {
145  $enabled[$mime] = $def;
146  }
147  }
148  return $enabled;
149  }
150 
151  public function enablePrefixWildcardQuery($a_stat)
152  {
153  $this->prefix_wildcard = $a_stat;
154  }
155 
157  {
158  return $this->prefix_wildcard;
159  }
160 
161  // end-patch mime_filter
162 
168  static function _getSearchSettingRefId()
169  {
170  global $ilDB;
171 
172  static $seas_ref_id = 0;
173 
174  if($seas_ref_id)
175  {
176  return $seas_ref_id;
177  }
178  $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data ".
179  "WHERE tree.parent = ".$ilDB->quote(SYSTEM_FOLDER_ID,'integer')." ".
180  "AND object_data.type = 'seas' ".
181  "AND object_reference.ref_id = tree.child ".
182  "AND object_reference.obj_id = object_data.obj_id";
183 
184  $res = $ilDB->query($query);
186 
187  return $seas_ref_id = $row->ref_id;
188  }
189 
190  function enabledIndex()
191  {
192  global $ilDB;
193 
194  if($ilDB->getDBType() == 'oracle')
195  {
196  return false;
197  }
198  return $this->index ? true : false;
199  }
200  function enableIndex($a_status)
201  {
202  $this->index = $a_status;
203  }
204  function enabledLucene()
205  {
206  return $this->lucene ? true : false;
207  }
208  function enableLucene($a_status)
209  {
210  $this->lucene = $a_status ? true : false;
211  }
212 
213  function getMaxHits()
214  {
215  return $this->max_hits;
216  }
217  function setMaxHits($a_max_hits)
218  {
219  $this->max_hits = $a_max_hits;
220  }
221 
222  public function getDefaultOperator()
223  {
225  }
226 
227  public function setDefaultOperator($a_op)
228  {
229  $this->default_operator = $a_op;
230  }
231 
232  public function setFragmentSize($a_size)
233  {
234  $this->fragmentSize = $a_size;
235  }
236 
237  public function getFragmentSize()
238  {
239  return $this->fragmentSize;
240  }
241 
242  public function setFragmentCount($a_count)
243  {
244  $this->fragmentCount = $a_count;
245  }
246 
247  public function getHideAdvancedSearch()
248  {
249  return $this->hide_adv_search ? true : false;
250  }
251  public function setHideAdvancedSearch($a_status)
252  {
253  $this->hide_adv_search = $a_status;
254  }
255  public function getAutoCompleteLength()
256  {
258  }
260  {
261  $this->auto_complete_length = $auto_complete_length;
262  }
263 
264  public function getFragmentCount()
265  {
266  return $this->fragmentCount;
267  }
268 
269  public function setMaxSubitems($a_max)
270  {
271  $this->numSubitems = $a_max;
272  }
273 
274  public function getMaxSubitems()
275  {
276  return $this->numSubitems;
277  }
278 
279  public function isRelevanceVisible()
280  {
281  return $this->showRelevance;
282  }
283 
284  public function showRelevance($a_status)
285  {
286  $this->showRelevance = (bool) $a_status;
287  }
288 
289  public function getLastIndexTime()
290  {
291  return $this->last_index_date instanceof ilDateTime ?
292  $this->last_index_date :
293  new ilDateTime('2009-01-01 12:00:00',IL_CAL_DATETIME);
294  }
295 
296  public function enableLuceneItemFilter($a_status)
297  {
298  $this->lucene_item_filter_enabled = $a_status;
299  }
300 
301  public function isLuceneItemFilterEnabled()
302  {
304  }
305 
306  public function getLuceneItemFilter()
307  {
309  }
310 
311 
312  public function setLuceneItemFilter($a_filter)
313  {
314  $this->lucene_item_filter = $a_filter;
315  }
316 
317  public function enableLuceneOfflineFilter($a_stat)
318  {
319  $this->lucene_offline_filter = $a_stat;
320  }
321 
323  {
325  }
326 
327  public function showSubRelevance($a_stat)
328  {
329  $this->showSubRelevance = $a_stat;
330  }
331 
332  public function isSubRelevanceVisible()
333  {
335  }
336 
337 
338  public function setLuceneMimeFilter($a_filter)
339  {
340  $this->lucene_mime_filter = $a_filter;
341  }
342 
343  public function getLuceneMimeFilter()
344  {
346  }
347 
351  public function isLuceneMimeFilterEnabled()
352  {
354  }
355 
360  public function enableLuceneMimeFilter($a_stat)
361  {
362  $this->lucene_mime_filter_enabled = $a_stat;
363  }
364 
365 
369  public function setLastIndexTime($time)
370  {
371  $this->last_index_date = $time;
372  }
373 
378  public function isLuceneUserSearchEnabled()
379  {
380  return $this->user_search;
381  }
382 
387  public function enableLuceneUserSearch($a_status)
388  {
389  $this->user_search = $a_status;
390  }
391 
397  public function showInactiveUser($a_visible)
398  {
399  $this->show_inactiv_user = (bool) $a_visible;
400  }
401 
407  public function isInactiveUserVisible()
408  {
410  }
411 
417  public function showLimitedUser($a_visible)
418  {
419  $this->show_limited_user = (bool) $a_visible;
420  }
421 
427  public function isLimitedUserVisible()
428  {
430  }
431 
432  public function isDateFilterEnabled()
433  {
434  return $this->date_filter;
435  }
436 
437  public function enableDateFilter($a_filter)
438  {
439  $this->date_filter = $a_filter;
440  }
441 
442  function update()
443  {
444  global $ilSetting;
445 
446  $this->ilias->setSetting('search_max_hits',$this->getMaxHits());
447  $this->ilias->setSetting('search_index',(int) $this->enabledIndex());
448  $this->ilias->setSetting('search_lucene',(int) $this->enabledLucene());
449 
450  $this->ilias->setSetting('lucene_default_operator',$this->getDefaultOperator());
451  $this->ilias->setSetting('lucene_fragment_size',$this->getFragmentSize());
452  $this->ilias->setSetting('lucene_fragment_count',$this->getFragmentCount());
453  $this->ilias->setSetting('lucene_max_subitems',$this->getMaxSubitems());
454  $this->ilias->setSetting('lucene_show_relevance',$this->isRelevanceVisible());
455  $this->ilias->setSetting('lucene_last_index_time',$this->getLastIndexTime()->get(IL_CAL_UNIX));
456  $this->ilias->setSetting('hide_adv_search',(int) $this->getHideAdvancedSearch());
457  $this->ilias->setSetting('auto_complete_length',(int) $this->getAutoCompleteLength());
458  $this->ilias->setSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled());
459  $this->ilias->setSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
460  $this->ilias->setSetting('lucene_offline_filter',(int) $this->isLuceneOfflineFilterEnabled());
461  $this->ilias->setSetting('lucene_mime_filter',serialize($this->getLuceneMimeFilter()));
462  $this->ilias->setSetting('lucene_sub_relevance',$this->isSubRelevanceVisible());
463  $ilSetting->set('lucene_mime_filter_enabled',$this->isLuceneMimeFilterEnabled());
464  $this->ilias->setSetting('lucene_prefix_wildcard',$this->isPrefixWildcardQueryEnabled());
465  $ilSetting->set('lucene_user_search',$this->isLuceneUserSearchEnabled());
466  $ilSetting->set('search_show_inactiv_user', $this->isInactiveUserVisible());
467  $ilSetting->set('search_show_limited_user', $this->isLimitedUserVisible());
468 
469  $ilSetting->set('search_date_filter', $this->isDateFilterEnabled());
470 
471  return true;
472  }
473 
474  // PRIVATE
475  function __read()
476  {
477  global $ilSetting;
478 
479  $this->setMaxHits($this->ilias->getSetting('search_max_hits',10));
480  $this->enableIndex($this->ilias->getSetting('search_index',0));
481  $this->enableLucene($this->ilias->getSetting('search_lucene',0));
482 
483  $this->setDefaultOperator($this->ilias->getSetting('lucene_default_operator',self::OPERATOR_AND));
484  $this->setFragmentSize($this->ilias->getSetting('lucene_fragment_size',50));
485  $this->setFragmentCount($this->ilias->getSetting('lucene_fragment_count',3));
486  $this->setMaxSubitems($this->ilias->getSetting('lucene_max_subitems',5));
487  $this->showRelevance($this->ilias->getSetting('lucene_show_relevance',true));
488 
489  if($time = $this->ilias->getSetting('lucene_last_index_time',false))
490  {
491  $this->setLastIndexTime(new ilDateTime($time,IL_CAL_UNIX));
492  }
493  else
494  {
495  $this->setLastIndexTime(null);
496  }
497 
498  $this->setHideAdvancedSearch($this->ilias->getSetting('hide_adv_search',0));
499  $this->setAutoCompleteLength($this->ilias->getSetting('auto_complete_length',$this->getAutoCompleteLength()));
500 
501  $this->enableLuceneItemFilter($this->ilias->getSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled()));
502 
503  $filter = $this->ilias->getSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
504  $this->setLuceneItemFilter(unserialize($filter));
505  $this->enableLuceneOfflineFilter($this->ilias->getSetting('lucene_offline_filter'), $this->isLuceneOfflineFilterEnabled());
506 
507  $this->enableLuceneMimeFilter($ilSetting->get('lucene_mime_filter_enabled',$this->lucene_item_filter_enabled));
508  $filter = $this->ilias->getSetting('lucene_mime_filter',serialize($this->getLuceneMimeFilter()));
509  $this->setLuceneMimeFilter(unserialize($filter));
510  $this->showSubRelevance($this->ilias->getSetting('lucene_sub_relevance',$this->showSubRelevance));
511  $this->enablePrefixWildcardQuery($this->ilias->getSetting('lucene_prefix_wildcard',$this->prefix_wildcard));
512  $this->enableLuceneUserSearch($ilSetting->get('lucene_user_search',$this->user_search));
513 
514  $this->showInactiveUser($ilSetting->get('search_show_inactiv_user', $this->show_inactiv_user));
515  $this->showLimitedUser($ilSetting->get('search_show_limited_user', $this->show_limited_user));
516 
517  $this->enableDateFilter($ilSetting->get('search_date_filter', $this->date_filter));
518  }
519 }
520 ?>
isLuceneMimeFilterEnabled()
Check if lucene mime filter is enabled.
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
const IL_CAL_DATETIME
isInactiveUserVisible()
are inactive user visible in user search
getEnabledLuceneItemFilterDefinitions()
Get lucene item filter definitions.
setAutoCompleteLength($auto_complete_length)
const IL_CAL_UNIX
static getLuceneMimeFilterDefinitions()
static _getSearchSettingRefId()
Read the ref_id of Search Settings object.
Date and time handling
redirection script todo: (a better solution should control the processing via a xml file) ...
isLimitedUserVisible()
are user with limited access visible in user search
enableLuceneMimeFilter($a_stat)
Enable lucene mime filter.
showLimitedUser($a_visible)
show user with limited access in user search
Create styles array
The data for the language used.
showInactiveUser($a_visible)
show inactive user in user search
isLuceneUserSearchEnabled()
Check if user search is enabled.
global $ilSetting
Definition: privfeed.php:17
global $ilDB
enableLuceneUserSearch($a_status)
Enable lucene user search.