ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilias;
54
55 $this->ilias = $ilias;
56 $this->__read();
57 }
58
65 public static function getInstance()
66 {
67 if (self::$instance == null) {
68 return self::$instance = new ilSearchSettings();
69 }
70 return self::$instance;
71 }
72
78 public static function getLuceneItemFilterDefinitions()
79 {
80 return array(
81 'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
82 'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
83 'lms' => array('filter' => 'type:lm OR type:htlm OR type:sahs OR type:dbk','trans' => 'learning_resource'),
84 'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
85 'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
86 'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
87 'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
88 'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
89 'file' => array('filter' => 'type:file','trans' => 'objs_file'),
90 'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
91 'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki')
92 );
93 }
94
95 public static function getLuceneMimeFilterDefinitions()
96 {
97 return array(
98 'pdf' => array('filter' => 'mimeType:pdf','trans' => 'search_mime_pdf'),
99 'word' => array('filter' => 'mimeType:word','trans' => 'search_mime_word'),
100 'excel' => array('filter' => 'mimeType:excel','trans' => 'search_mime_excel'),
101 'powerpoint' => array('filter' => 'mimeType:powerpoint','trans' => 'search_mime_powerpoint'),
102 'image' => array('filter' => 'mimeType:image','trans' => 'search_mime_image')
103 );
104 }
105
112 {
113 if (!$this->isLuceneItemFilterEnabled()) {
114 return array();
115 }
116
117 $filter = $this->getLuceneItemFilter();
118 $enabled = array();
119 foreach (self::getLuceneItemFilterDefinitions() as $obj => $def) {
120 if (isset($filter[$obj]) and $filter[$obj]) {
121 $enabled[$obj] = $def;
122 }
123 }
124 return $enabled;
125 }
126
127 // begin-patch mime_filter
129 {
130 if (!$this->isLuceneItemFilterEnabled()) {
131 return array();
132 }
133
134 $filter = $this->getLuceneMimeFilter();
135 $enabled = array();
136 foreach (self::getLuceneMimeFilterDefinitions() as $mime => $def) {
137 if (isset($filter[$mime]) and $filter[$mime]) {
138 $enabled[$mime] = $def;
139 }
140 }
141 return $enabled;
142 }
143
144 public function enablePrefixWildcardQuery($a_stat)
145 {
146 $this->prefix_wildcard = $a_stat;
147 }
148
150 {
152 }
153
154 // end-patch mime_filter
155
161 public static function _getSearchSettingRefId()
162 {
163 global $ilDB;
164
165 static $seas_ref_id = 0;
166
167 if ($seas_ref_id) {
168 return $seas_ref_id;
169 }
170 $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data " .
171 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
172 "AND object_data.type = 'seas' " .
173 "AND object_reference.ref_id = tree.child " .
174 "AND object_reference.obj_id = object_data.obj_id";
175
176 $res = $ilDB->query($query);
178
179 return $seas_ref_id = $row->ref_id;
180 }
181
182 public function enabledIndex()
183 {
184 global $ilDB;
185
186 if ($ilDB->getDBType() == 'oracle') {
187 return false;
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 $ilSetting;
436
437 $this->ilias->setSetting('search_max_hits', $this->getMaxHits());
438 $this->ilias->setSetting('search_index', (int) $this->enabledIndex());
439 $this->ilias->setSetting('search_lucene', (int) $this->enabledLucene());
440
441 $this->ilias->setSetting('lucene_default_operator', $this->getDefaultOperator());
442 $this->ilias->setSetting('lucene_fragment_size', $this->getFragmentSize());
443 $this->ilias->setSetting('lucene_fragment_count', $this->getFragmentCount());
444 $this->ilias->setSetting('lucene_max_subitems', $this->getMaxSubitems());
445 $this->ilias->setSetting('lucene_show_relevance', $this->isRelevanceVisible());
446 $this->ilias->setSetting('lucene_last_index_time', $this->getLastIndexTime()->get(IL_CAL_UNIX));
447 $this->ilias->setSetting('hide_adv_search', (int) $this->getHideAdvancedSearch());
448 $this->ilias->setSetting('auto_complete_length', (int) $this->getAutoCompleteLength());
449 $this->ilias->setSetting('lucene_item_filter_enabled', (int) $this->isLuceneItemFilterEnabled());
450 $this->ilias->setSetting('lucene_item_filter', serialize($this->getLuceneItemFilter()));
451 $this->ilias->setSetting('lucene_offline_filter', (int) $this->isLuceneOfflineFilterEnabled());
452 $this->ilias->setSetting('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
453 $this->ilias->setSetting('lucene_sub_relevance', $this->isSubRelevanceVisible());
454 $ilSetting->set('lucene_mime_filter_enabled', $this->isLuceneMimeFilterEnabled());
455 $this->ilias->setSetting('lucene_prefix_wildcard', $this->isPrefixWildcardQueryEnabled());
456 $ilSetting->set('lucene_user_search', $this->isLuceneUserSearchEnabled());
457 $ilSetting->set('search_show_inactiv_user', $this->isInactiveUserVisible());
458 $ilSetting->set('search_show_limited_user', $this->isLimitedUserVisible());
459
460 $ilSetting->set('search_date_filter', $this->isDateFilterEnabled());
461
462 return true;
463 }
464
465 // PRIVATE
466 public function __read()
467 {
468 global $ilSetting;
469
470 $this->setMaxHits($this->ilias->getSetting('search_max_hits', 10));
471 $this->enableIndex($this->ilias->getSetting('search_index', 0));
472 $this->enableLucene($this->ilias->getSetting('search_lucene', 0));
473
474 $this->setDefaultOperator($this->ilias->getSetting('lucene_default_operator', self::OPERATOR_AND));
475 $this->setFragmentSize($this->ilias->getSetting('lucene_fragment_size', 50));
476 $this->setFragmentCount($this->ilias->getSetting('lucene_fragment_count', 3));
477 $this->setMaxSubitems($this->ilias->getSetting('lucene_max_subitems', 5));
478 $this->showRelevance($this->ilias->getSetting('lucene_show_relevance', true));
479
480 if ($time = $this->ilias->getSetting('lucene_last_index_time', false)) {
482 } else {
483 $this->setLastIndexTime(null);
484 }
485
486 $this->setHideAdvancedSearch($this->ilias->getSetting('hide_adv_search', 0));
487 $this->setAutoCompleteLength($this->ilias->getSetting('auto_complete_length', $this->getAutoCompleteLength()));
488
489 $this->enableLuceneItemFilter($this->ilias->getSetting('lucene_item_filter_enabled', (int) $this->isLuceneItemFilterEnabled()));
490
491 $filter = $this->ilias->getSetting('lucene_item_filter', serialize($this->getLuceneItemFilter()));
492 $this->setLuceneItemFilter(unserialize($filter));
493 $this->enableLuceneOfflineFilter($this->ilias->getSetting('lucene_offline_filter'), $this->isLuceneOfflineFilterEnabled());
494
495 $this->enableLuceneMimeFilter($ilSetting->get('lucene_mime_filter_enabled', $this->lucene_item_filter_enabled));
496 $filter = $this->ilias->getSetting('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
497 $this->setLuceneMimeFilter(unserialize($filter));
498 $this->showSubRelevance($this->ilias->getSetting('lucene_sub_relevance', $this->showSubRelevance));
499 $this->enablePrefixWildcardQuery($this->ilias->getSetting('lucene_prefix_wildcard', $this->prefix_wildcard));
500 $this->enableLuceneUserSearch($ilSetting->get('lucene_user_search', $this->user_search));
501
502 $this->showInactiveUser($ilSetting->get('search_show_inactiv_user', $this->show_inactiv_user));
503 $this->showLimitedUser($ilSetting->get('search_show_limited_user', $this->show_limited_user));
504
505 $this->enableDateFilter($ilSetting->get('search_date_filter', $this->date_filter));
506 }
507}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
@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()
$def
Definition: croninfo.php:21
$time
Definition: cron.php:21
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