ILIAS  release_8 Revision v8.24
class.ilSearchSettings.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
16{
17 public const LIKE_SEARCH = 0;
18 public const LUCENE_SEARCH = 2;
19
20 public const OPERATOR_AND = 1;
21 public const OPERATOR_OR = 2;
22
23 protected static ?ilSearchSettings $instance = null;
24
26 protected int $fragmentSize = 30;
27 protected int $fragmentCount = 3;
28 protected int $numSubitems = 5;
29 protected bool $showRelevance = true;
30 protected ?ilDateTime $last_index_date = null;
31 protected bool $lucene_item_filter_enabled = false;
32 protected array $lucene_item_filter = array();
33 protected bool $lucene_offline_filter = true;
34 protected int $auto_complete_length = 10;
35 protected bool $show_inactiv_user = true;
36 protected bool $show_limited_user = true;
37
38 protected bool $lucene = false;
39 protected bool $hide_adv_search = false;
40 protected bool $lucene_mime_filter_enabled = false;
41 protected array $lucene_mime_filter = array();
42 protected bool $showSubRelevance = false;
43 protected bool $prefix_wildcard = false;
44 protected bool $user_search = false;
45 protected bool $date_filter = false;
46
47 protected ?ILIAS $ilias = null;
49 private int $max_hits = 10;
50
51 public function __construct()
52 {
53 global $DIC;
54
55 $this->ilias = $DIC['ilias'];
56 $this->setting = $DIC->settings();
57 $this->__read();
58 }
59
60 public static function getInstance(): ilSearchSettings
61 {
62 if (self::$instance instanceof ilSearchSettings) {
63 return self::$instance;
64 }
65 return self::$instance = new ilSearchSettings();
66 }
67
72 public static function getLuceneItemFilterDefinitions(): array
73 {
74 return array(
75 'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
76 'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
77 'lms' => array('filter' => 'type:lm OR type:htlm','trans' => 'obj_lrss'),
78 'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
79 'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
80 'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
81 'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
82 'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
83 'file' => array('filter' => 'type:file','trans' => 'objs_file'),
84 'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
85 'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki'),
86 'copa' => array('filter' => 'type:copa','trans' => 'objs_copa'),
87 );
88 }
89
90 public static function getLuceneMimeFilterDefinitions(): array
91 {
92 return array(
93 'pdf' => array('filter' => 'mimeType:pdf','trans' => 'search_mime_pdf'),
94 'word' => array('filter' => 'mimeType:word','trans' => 'search_mime_word'),
95 'excel' => array('filter' => 'mimeType:excel','trans' => 'search_mime_excel'),
96 'powerpoint' => array('filter' => 'mimeType:powerpoint','trans' => 'search_mime_powerpoint'),
97 'image' => array('filter' => 'mimeType:image','trans' => 'search_mime_image')
98 );
99 }
100
106 {
107 if (!$this->isLuceneItemFilterEnabled()) {
108 return array();
109 }
110
111 $filter = $this->getLuceneItemFilter();
112 $enabled = array();
113 foreach (self::getLuceneItemFilterDefinitions() as $obj => $def) {
114 if (isset($filter[$obj]) and $filter[$obj]) {
115 $enabled[$obj] = $def;
116 }
117 }
118 return $enabled;
119 }
120
121 // begin-patch mime_filter
123 {
124 if (!$this->isLuceneItemFilterEnabled()) {
125 return array();
126 }
127
128 $filter = $this->getLuceneMimeFilter();
129 $enabled = array();
130 foreach (self::getLuceneMimeFilterDefinitions() as $mime => $def) {
131 if (isset($filter[$mime]) and $filter[$mime]) {
132 $enabled[$mime] = $def;
133 }
134 }
135 return $enabled;
136 }
137
138 public function enablePrefixWildcardQuery(bool $a_stat): void
139 {
140 $this->prefix_wildcard = $a_stat;
141 }
142
143 public function isPrefixWildcardQueryEnabled(): bool
144 {
146 }
147
151 public static function _getSearchSettingRefId(): int
152 {
153 global $DIC;
154
155 $ilDB = $DIC->database();
156
157 static $seas_ref_id = 0;
158
159 if ($seas_ref_id) {
160 return $seas_ref_id;
161 }
162 $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data " .
163 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
164 "AND object_data.type = 'seas' " .
165 "AND object_reference.ref_id = tree.child " .
166 "AND object_reference.obj_id = object_data.obj_id";
167
168 $res = $ilDB->query($query);
169 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
170
171 return $seas_ref_id = (int) $row->ref_id;
172 }
173
174 public function enabledLucene(): bool
175 {
176 return $this->lucene;
177 }
178 public function enableLucene(bool $a_status): void
179 {
180 $this->lucene = $a_status;
181 }
182
183 public function getMaxHits(): int
184 {
185 return $this->max_hits;
186 }
187 public function setMaxHits(int $a_max_hits): void
188 {
189 $this->max_hits = $a_max_hits;
190 }
191
192 public function getDefaultOperator(): int
193 {
195 }
196
197 public function setDefaultOperator(int $a_op): void
198 {
199 $this->default_operator = $a_op;
200 }
201
202 public function setFragmentSize(int $a_size): void
203 {
204 $this->fragmentSize = $a_size;
205 }
206
207 public function getFragmentSize(): int
208 {
209 return $this->fragmentSize;
210 }
211
212 public function setFragmentCount(int $a_count): void
213 {
214 $this->fragmentCount = $a_count;
215 }
216
217 public function getHideAdvancedSearch(): bool
218 {
220 }
221 public function setHideAdvancedSearch(bool $a_status): void
222 {
223 $this->hide_adv_search = $a_status;
224 }
225 public function getAutoCompleteLength(): int
226 {
228 }
230 {
231 $this->auto_complete_length = $auto_complete_length;
232 }
233
234 public function getFragmentCount(): int
235 {
237 }
238
239 public function setMaxSubitems(int $a_max): void
240 {
241 $this->numSubitems = $a_max;
242 }
243
244 public function getMaxSubitems(): int
245 {
246 return $this->numSubitems;
247 }
248
249 public function isRelevanceVisible(): bool
250 {
252 }
253
254 public function showRelevance(bool $a_status): void
255 {
256 $this->showRelevance = $a_status;
257 }
258
259 public function getLastIndexTime(): ilDateTime
260 {
261 return $this->last_index_date instanceof ilDateTime ?
262 $this->last_index_date :
263 new ilDateTime('2009-01-01 12:00:00', IL_CAL_DATETIME);
264 }
265
266 public function enableLuceneItemFilter(bool $a_status): void
267 {
268 $this->lucene_item_filter_enabled = $a_status;
269 }
270
271 public function isLuceneItemFilterEnabled(): bool
272 {
274 }
275
276 public function getLuceneItemFilter(): array
277 {
279 }
280
281
282 public function setLuceneItemFilter(array $a_filter): void
283 {
284 $this->lucene_item_filter = $a_filter;
285 }
286
287 public function enableLuceneOfflineFilter(bool $a_stat): void
288 {
289 $this->lucene_offline_filter = $a_stat;
290 }
291
292 public function isLuceneOfflineFilterEnabled(): bool
293 {
295 }
296
297 public function showSubRelevance(bool $a_stat): void
298 {
299 $this->showSubRelevance = $a_stat;
300 }
301
302 public function isSubRelevanceVisible(): bool
303 {
305 }
306
307
308 public function setLuceneMimeFilter(array $a_filter): void
309 {
310 $this->lucene_mime_filter = $a_filter;
311 }
312
313 public function getLuceneMimeFilter(): array
314 {
316 }
317
321 public function isLuceneMimeFilterEnabled(): bool
322 {
324 }
325
326 public function enableLuceneMimeFilter(bool $a_stat): void
327 {
328 $this->lucene_mime_filter_enabled = $a_stat;
329 }
330
331
332 public function setLastIndexTime(?ilDateTime $time): void
333 {
334 $this->last_index_date = $time;
335 }
336
340 public function isLuceneUserSearchEnabled(): bool
341 {
342 return $this->user_search;
343 }
344
349 public function enableLuceneUserSearch(bool $a_status): void
350 {
351 $this->user_search = $a_status;
352 }
353
357 public function showInactiveUser(bool $a_visible): void
358 {
359 $this->show_inactiv_user = $a_visible;
360 }
361
366 public function isInactiveUserVisible(): bool
367 {
369 }
370
374 public function showLimitedUser(bool $a_visible): void
375 {
376 $this->show_limited_user = $a_visible;
377 }
378
379
380 public function isLimitedUserVisible(): bool
381 {
383 }
384
385 public function isDateFilterEnabled(): bool
386 {
387 return $this->date_filter;
388 }
389
390 public function enableDateFilter(bool $a_filter): void
391 {
392 $this->date_filter = $a_filter;
393 }
394
395 public function update(): void
396 {
397 $this->setting->set('search_max_hits', (string) $this->getMaxHits());
398 $this->setting->set('search_lucene', (string) $this->enabledLucene());
399
400 $this->setting->set('lucene_default_operator', (string) $this->getDefaultOperator());
401 $this->setting->set('lucene_fragment_size', (string) $this->getFragmentSize());
402 $this->setting->set('lucene_fragment_count', (string) $this->getFragmentCount());
403 $this->setting->set('lucene_max_subitems', (string) $this->getMaxSubitems());
404 $this->setting->set('lucene_show_relevance', (string) $this->isRelevanceVisible());
405 $this->setting->set('lucene_last_index_time', (string) $this->getLastIndexTime()->get(IL_CAL_UNIX));
406 $this->setting->set('hide_adv_search', (string) $this->getHideAdvancedSearch());
407 $this->setting->set('auto_complete_length', (string) $this->getAutoCompleteLength());
408 $this->setting->set('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled());
409 $this->setting->set('lucene_item_filter', serialize($this->getLuceneItemFilter()));
410 $this->setting->set('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled());
411 $this->setting->set('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
412 $this->setting->set('lucene_sub_relevance', (string) $this->isSubRelevanceVisible());
413 $this->setting->set('lucene_mime_filter_enabled', (string) $this->isLuceneMimeFilterEnabled());
414 $this->setting->set('lucene_prefix_wildcard', (string) $this->isPrefixWildcardQueryEnabled());
415 $this->setting->set('lucene_user_search', (string) $this->isLuceneUserSearchEnabled());
416 $this->setting->set('search_show_inactiv_user', (string) $this->isInactiveUserVisible());
417 $this->setting->set('search_show_limited_user', (string) $this->isLimitedUserVisible());
418 $this->setting->set('search_date_filter', (string) $this->isDateFilterEnabled());
419 }
420
421 // PRIVATE
422 protected function __read()
423 {
424 $this->setMaxHits((int) $this->setting->get('search_max_hits', '10'));
425 $this->enableLucene((bool) $this->setting->get('search_lucene', '0'));
426 $this->setDefaultOperator((int) $this->setting->get('lucene_default_operator', (string) self::OPERATOR_AND));
427 $this->setFragmentSize((int) $this->setting->get('lucene_fragment_size', "50"));
428 $this->setFragmentCount((int) $this->setting->get('lucene_fragment_count', "3"));
429 $this->setMaxSubitems((int) $this->setting->get('lucene_max_subitems', "5"));
430 $this->showRelevance((bool) $this->setting->get('lucene_show_relevance', "1"));
431 if ($time = $this->setting->get('lucene_last_index_time', '0')) {
432 $this->setLastIndexTime(new ilDateTime($time, IL_CAL_UNIX));
433 } else {
434 $this->setLastIndexTime(null);
435 }
436 $this->setHideAdvancedSearch((bool) $this->setting->get('hide_adv_search', '0'));
437 $this->setAutoCompleteLength((int) $this->setting->get('auto_complete_length', (string) $this->getAutoCompleteLength()));
438 $this->enableLuceneItemFilter((bool) $this->setting->get('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled()));
439 $filter = (string) $this->setting->get('lucene_item_filter', serialize($this->getLuceneItemFilter()));
440 $this->setLuceneItemFilter(unserialize($filter));
441 $this->enableLuceneOfflineFilter((bool) $this->setting->get('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled()));
442 $this->enableLuceneMimeFilter((bool) $this->setting->get('lucene_mime_filter_enabled', (string) $this->lucene_item_filter_enabled));
443 $filter = (string) $this->setting->get('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
444 $this->setLuceneMimeFilter(unserialize($filter));
445 $this->showSubRelevance((bool) $this->setting->get('lucene_sub_relevance', (string) $this->showSubRelevance));
446 $this->enablePrefixWildcardQuery((bool) $this->setting->get('lucene_prefix_wildcard', (string) $this->prefix_wildcard));
447 $this->enableLuceneUserSearch((bool) $this->setting->get('lucene_user_search', (string) $this->user_search));
448 $this->showInactiveUser((bool) $this->setting->get('search_show_inactiv_user', (string) $this->show_inactiv_user));
449 $this->showLimitedUser((bool) $this->setting->get('search_show_limited_user', (string) $this->show_limited_user));
450 $this->enableDateFilter((bool) $this->setting->get('search_date_filter', (string) $this->date_filter));
451 }
452}
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
static ilSearchSettings $instance
isLuceneMimeFilterEnabled()
Check if lucene mime filter is enabled.
enablePrefixWildcardQuery(bool $a_stat)
showRelevance(bool $a_status)
enableLuceneUserSearch(bool $a_status)
Enable lucene user search.
setAutoCompleteLength(int $auto_complete_length)
setLuceneMimeFilter(array $a_filter)
enableLucene(bool $a_status)
static _getSearchSettingRefId()
Read the ref_id of Search Settings object.
enableDateFilter(bool $a_filter)
setMaxHits(int $a_max_hits)
isInactiveUserVisible()
are inactive user visible in user search
setLuceneItemFilter(array $a_filter)
showSubRelevance(bool $a_stat)
setLastIndexTime(?ilDateTime $time)
enableLuceneMimeFilter(bool $a_stat)
getEnabledLuceneItemFilterDefinitions()
Get lucene item filter definitions.
enableLuceneItemFilter(bool $a_status)
setHideAdvancedSearch(bool $a_status)
setFragmentCount(int $a_count)
isLuceneUserSearchEnabled()
Check if user search is enabled.
showLimitedUser(bool $a_visible)
show user with limited access in user search
enableLuceneOfflineFilter(bool $a_stat)
static getLuceneMimeFilterDefinitions()
showInactiveUser(bool $a_visible)
show inactive user in user search
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
Class ChatMainBarProvider \MainMenu\Provider.
header include for all ilias files.
$query