ILIAS  release_7 Revision v7.30-3-g800a261c036
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 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 public $ilias = null;
48 public $max_hits = null;
49 public $index = null;
50
51 public function __construct()
52 {
53 global $DIC;
54
55 $ilias = $DIC['ilias'];
56
57 $this->ilias = $ilias;
58 $this->__read();
59 }
60
67 public static function getInstance()
68 {
69 if (self::$instance == null) {
70 return self::$instance = new ilSearchSettings();
71 }
72 return self::$instance;
73 }
74
80 public static function getLuceneItemFilterDefinitions()
81 {
82 return array(
83 'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
84 'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
85 'lms' => array('filter' => 'type:lm OR type:htlm','trans' => 'obj_lrss'),
86 'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
87 'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
88 'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
89 'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
90 'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
91 'file' => array('filter' => 'type:file','trans' => 'objs_file'),
92 'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
93 'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki'),
94 'copa' => array('filter' => 'type:copa','trans' => 'objs_copa'),
95 );
96 }
97
98 public static function getLuceneMimeFilterDefinitions()
99 {
100 return array(
101 'pdf' => array('filter' => 'mimeType:pdf','trans' => 'search_mime_pdf'),
102 'word' => array('filter' => 'mimeType:word','trans' => 'search_mime_word'),
103 'excel' => array('filter' => 'mimeType:excel','trans' => 'search_mime_excel'),
104 'powerpoint' => array('filter' => 'mimeType:powerpoint','trans' => 'search_mime_powerpoint'),
105 'image' => array('filter' => 'mimeType:image','trans' => 'search_mime_image')
106 );
107 }
108
115 {
116 if (!$this->isLuceneItemFilterEnabled()) {
117 return array();
118 }
119
120 $filter = $this->getLuceneItemFilter();
121 $enabled = array();
122 foreach (self::getLuceneItemFilterDefinitions() as $obj => $def) {
123 if (isset($filter[$obj]) and $filter[$obj]) {
124 $enabled[$obj] = $def;
125 }
126 }
127 return $enabled;
128 }
129
130 // begin-patch mime_filter
132 {
133 if (!$this->isLuceneItemFilterEnabled()) {
134 return array();
135 }
136
137 $filter = $this->getLuceneMimeFilter();
138 $enabled = array();
139 foreach (self::getLuceneMimeFilterDefinitions() as $mime => $def) {
140 if (isset($filter[$mime]) and $filter[$mime]) {
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 {
155 }
156
157 // end-patch mime_filter
158
164 public static function _getSearchSettingRefId()
165 {
166 global $DIC;
167
168 $ilDB = $DIC['ilDB'];
169
170 static $seas_ref_id = 0;
171
172 if ($seas_ref_id) {
173 return $seas_ref_id;
174 }
175 $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data " .
176 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
177 "AND object_data.type = 'seas' " .
178 "AND object_reference.ref_id = tree.child " .
179 "AND object_reference.obj_id = object_data.obj_id";
180
181 $res = $ilDB->query($query);
182 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
183
184 return $seas_ref_id = $row->ref_id;
185 }
186
187 public function enabledIndex()
188 {
189 return $this->index ? true : false;
190 }
191 public function enableIndex($a_status)
192 {
193 $this->index = $a_status;
194 }
195 public function enabledLucene()
196 {
197 return $this->lucene ? true : false;
198 }
199 public function enableLucene($a_status)
200 {
201 $this->lucene = $a_status ? true : false;
202 }
203
204 public function getMaxHits()
205 {
206 return $this->max_hits;
207 }
208 public function setMaxHits($a_max_hits)
209 {
210 $this->max_hits = $a_max_hits;
211 }
212
213 public function getDefaultOperator()
214 {
216 }
217
218 public function setDefaultOperator($a_op)
219 {
220 $this->default_operator = $a_op;
221 }
222
223 public function setFragmentSize($a_size)
224 {
225 $this->fragmentSize = $a_size;
226 }
227
228 public function getFragmentSize()
229 {
230 return $this->fragmentSize;
231 }
232
233 public function setFragmentCount($a_count)
234 {
235 $this->fragmentCount = $a_count;
236 }
237
238 public function getHideAdvancedSearch()
239 {
240 return $this->hide_adv_search ? true : false;
241 }
242 public function setHideAdvancedSearch($a_status)
243 {
244 $this->hide_adv_search = $a_status;
245 }
246 public function getAutoCompleteLength()
247 {
249 }
251 {
252 $this->auto_complete_length = $auto_complete_length;
253 }
254
255 public function getFragmentCount()
256 {
258 }
259
260 public function setMaxSubitems($a_max)
261 {
262 $this->numSubitems = $a_max;
263 }
264
265 public function getMaxSubitems()
266 {
267 return $this->numSubitems;
268 }
269
270 public function isRelevanceVisible()
271 {
273 }
274
275 public function showRelevance($a_status)
276 {
277 $this->showRelevance = (bool) $a_status;
278 }
279
280 public function getLastIndexTime()
281 {
282 return $this->last_index_date instanceof ilDateTime ?
283 $this->last_index_date :
284 new ilDateTime('2009-01-01 12:00:00', IL_CAL_DATETIME);
285 }
286
287 public function enableLuceneItemFilter($a_status)
288 {
289 $this->lucene_item_filter_enabled = $a_status;
290 }
291
293 {
295 }
296
297 public function getLuceneItemFilter()
298 {
300 }
301
302
303 public function setLuceneItemFilter($a_filter)
304 {
305 $this->lucene_item_filter = $a_filter;
306 }
307
308 public function enableLuceneOfflineFilter($a_stat)
309 {
310 $this->lucene_offline_filter = $a_stat;
311 }
312
314 {
316 }
317
318 public function showSubRelevance($a_stat)
319 {
320 $this->showSubRelevance = $a_stat;
321 }
322
323 public function isSubRelevanceVisible()
324 {
326 }
327
328
329 public function setLuceneMimeFilter($a_filter)
330 {
331 $this->lucene_mime_filter = $a_filter;
332 }
333
334 public function getLuceneMimeFilter()
335 {
337 }
338
343 {
345 }
346
351 public function enableLuceneMimeFilter($a_stat)
352 {
353 $this->lucene_mime_filter_enabled = $a_stat;
354 }
355
356
360 public function setLastIndexTime($time)
361 {
362 $this->last_index_date = $time;
363 }
364
370 {
371 return $this->user_search;
372 }
373
378 public function enableLuceneUserSearch($a_status)
379 {
380 $this->user_search = $a_status;
381 }
382
388 public function showInactiveUser($a_visible)
389 {
390 $this->show_inactiv_user = (bool) $a_visible;
391 }
392
398 public function isInactiveUserVisible()
399 {
401 }
402
408 public function showLimitedUser($a_visible)
409 {
410 $this->show_limited_user = (bool) $a_visible;
411 }
412
418 public function isLimitedUserVisible()
419 {
421 }
422
423 public function isDateFilterEnabled()
424 {
425 return $this->date_filter;
426 }
427
428 public function enableDateFilter($a_filter)
429 {
430 $this->date_filter = $a_filter;
431 }
432
433 public function update()
434 {
435 global $DIC;
436
437 $ilSetting = $DIC['ilSetting'];
438
439 $this->ilias->setSetting('search_max_hits', $this->getMaxHits());
440 $this->ilias->setSetting('search_index', (int) $this->enabledIndex());
441 $this->ilias->setSetting('search_lucene', (int) $this->enabledLucene());
442
443 $this->ilias->setSetting('lucene_default_operator', $this->getDefaultOperator());
444 $this->ilias->setSetting('lucene_fragment_size', $this->getFragmentSize());
445 $this->ilias->setSetting('lucene_fragment_count', $this->getFragmentCount());
446 $this->ilias->setSetting('lucene_max_subitems', $this->getMaxSubitems());
447 $this->ilias->setSetting('lucene_show_relevance', $this->isRelevanceVisible());
448 $this->ilias->setSetting('lucene_last_index_time', $this->getLastIndexTime()->get(IL_CAL_UNIX));
449 $this->ilias->setSetting('hide_adv_search', (int) $this->getHideAdvancedSearch());
450 $this->ilias->setSetting('auto_complete_length', (int) $this->getAutoCompleteLength());
451 $this->ilias->setSetting('lucene_item_filter_enabled', (int) $this->isLuceneItemFilterEnabled());
452 $this->ilias->setSetting('lucene_item_filter', serialize($this->getLuceneItemFilter()));
453 $this->ilias->setSetting('lucene_offline_filter', (int) $this->isLuceneOfflineFilterEnabled());
454 $this->ilias->setSetting('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
455 $this->ilias->setSetting('lucene_sub_relevance', $this->isSubRelevanceVisible());
456 $ilSetting->set('lucene_mime_filter_enabled', $this->isLuceneMimeFilterEnabled());
457 $this->ilias->setSetting('lucene_prefix_wildcard', $this->isPrefixWildcardQueryEnabled());
458 $ilSetting->set('lucene_user_search', $this->isLuceneUserSearchEnabled());
459 $ilSetting->set('search_show_inactiv_user', $this->isInactiveUserVisible());
460 $ilSetting->set('search_show_limited_user', $this->isLimitedUserVisible());
461
462 $ilSetting->set('search_date_filter', $this->isDateFilterEnabled());
463
464 return true;
465 }
466
467 // PRIVATE
468 public function __read()
469 {
470 global $DIC;
471
472 $ilSetting = $DIC['ilSetting'];
473
474 $this->setMaxHits($this->ilias->getSetting('search_max_hits', 10));
475 $this->enableIndex($this->ilias->getSetting('search_index', 0));
476 $this->enableLucene($this->ilias->getSetting('search_lucene', 0));
477
478 $this->setDefaultOperator($this->ilias->getSetting('lucene_default_operator', self::OPERATOR_AND));
479 $this->setFragmentSize($this->ilias->getSetting('lucene_fragment_size', 50));
480 $this->setFragmentCount($this->ilias->getSetting('lucene_fragment_count', 3));
481 $this->setMaxSubitems($this->ilias->getSetting('lucene_max_subitems', 5));
482 $this->showRelevance($this->ilias->getSetting('lucene_show_relevance', true));
483
484 if ($time = $this->ilias->getSetting('lucene_last_index_time', false)) {
485 $this->setLastIndexTime(new ilDateTime($time, IL_CAL_UNIX));
486 } else {
487 $this->setLastIndexTime(null);
488 }
489
490 $this->setHideAdvancedSearch($this->ilias->getSetting('hide_adv_search', 0));
491 $this->setAutoCompleteLength($this->ilias->getSetting('auto_complete_length', $this->getAutoCompleteLength()));
492
493 $this->enableLuceneItemFilter($this->ilias->getSetting('lucene_item_filter_enabled', (int) $this->isLuceneItemFilterEnabled()));
494
495 $filter = $this->ilias->getSetting('lucene_item_filter', serialize($this->getLuceneItemFilter()));
496 $this->setLuceneItemFilter(unserialize($filter));
497 $this->enableLuceneOfflineFilter($this->ilias->getSetting('lucene_offline_filter'), $this->isLuceneOfflineFilterEnabled());
498
499 $this->enableLuceneMimeFilter($ilSetting->get('lucene_mime_filter_enabled', $this->lucene_item_filter_enabled));
500 $filter = $this->ilias->getSetting('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
501 $this->setLuceneMimeFilter(unserialize($filter));
502 $this->showSubRelevance($this->ilias->getSetting('lucene_sub_relevance', $this->showSubRelevance));
503 $this->enablePrefixWildcardQuery($this->ilias->getSetting('lucene_prefix_wildcard', $this->prefix_wildcard));
504 $this->enableLuceneUserSearch($ilSetting->get('lucene_user_search', $this->user_search));
505
506 $this->showInactiveUser($ilSetting->get('search_show_inactiv_user', $this->show_inactiv_user));
507 $this->showLimitedUser($ilSetting->get('search_show_limited_user', $this->show_limited_user));
508
509 $this->enableDateFilter($ilSetting->get('search_date_filter', $this->date_filter));
510 }
511}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
@classDescription Date and time handling
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
isLuceneMimeFilterEnabled()
Check if lucene mime filter is enabled.
isLimitedUserVisible()
are user with limited access visible in user search
showLimitedUser($a_visible)
show user with limited access in user search
static _getSearchSettingRefId()
Read the ref_id of Search Settings object.
isInactiveUserVisible()
are inactive user visible in user search
enableLuceneMimeFilter($a_stat)
Enable lucene mime filter.
showInactiveUser($a_visible)
show inactive user in user search
setAutoCompleteLength($auto_complete_length)
enableLuceneUserSearch($a_status)
Enable lucene user search.
getEnabledLuceneItemFilterDefinitions()
Get lucene item filter definitions.
isLuceneUserSearchEnabled()
Check if user search is enabled.
static getLuceneMimeFilterDefinitions()
const SYSTEM_FOLDER_ID
Definition: constants.php:33
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
global $ilDB