ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSearchSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const int LIKE_SEARCH = 0;
27 public const int LUCENE_SEARCH = 2;
28
29 public const int OPERATOR_AND = 1;
30 public const int OPERATOR_OR = 2;
31
32 protected static ?ilSearchSettings $instance = null;
33
35 protected int $fragmentSize = 30;
36 protected int $fragmentCount = 3;
37 protected int $numSubitems = 5;
38 protected ?ilDateTime $last_index_date = null;
39 protected bool $lucene_item_filter_enabled = false;
40 protected array $lucene_item_filter = array();
41 protected bool $lucene_offline_filter = true;
42 protected int $auto_complete_length = 10;
43 protected bool $show_inactiv_user = true;
44 protected bool $show_limited_user = true;
45
46 protected bool $lucene = false;
47 protected bool $lucene_mime_filter_enabled = false;
48 protected array $lucene_mime_filter = array();
49 protected bool $prefix_wildcard = false;
50 protected bool $user_search = false;
51 protected bool $date_filter = false;
52
53 protected ?ILIAS $ilias = null;
55 private int $max_hits = 10;
56
57 public function __construct()
58 {
59 global $DIC;
60
61 $this->ilias = $DIC['ilias'];
62 $this->setting = $DIC->settings();
63 $this->__read();
64 }
65
66 public static function getInstance(): ilSearchSettings
67 {
68 if (self::$instance instanceof ilSearchSettings) {
69 return self::$instance;
70 }
71 return self::$instance = new ilSearchSettings();
72 }
73
78 public static function getLuceneItemFilterDefinitions(): array
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','trans' => 'obj_lrss'),
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 'copa' => array('filter' => 'type:copa','trans' => 'objs_copa'),
93 );
94 }
95
96 public static function getLuceneMimeFilterDefinitions(): array
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
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
128 {
129 if (!$this->isLuceneMimeFilterEnabled()) {
130 return array();
131 }
132
133 $filter = $this->getLuceneMimeFilter();
134 $enabled = array();
135 foreach (self::getLuceneMimeFilterDefinitions() as $mime => $def) {
136 if (isset($filter[$mime]) and $filter[$mime]) {
137 $enabled[$mime] = $def;
138 }
139 }
140 return $enabled;
141 }
142
143 public function enablePrefixWildcardQuery(bool $a_stat): void
144 {
145 $this->prefix_wildcard = $a_stat;
146 }
147
148 public function isPrefixWildcardQueryEnabled(): bool
149 {
151 }
152
156 public static function _getSearchSettingRefId(): int
157 {
158 global $DIC;
159
160 $ilDB = $DIC->database();
161
162 static $seas_ref_id = 0;
163
164 if ($seas_ref_id) {
165 return $seas_ref_id;
166 }
167 $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data " .
168 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
169 "AND object_data.type = 'seas' " .
170 "AND object_reference.ref_id = tree.child " .
171 "AND object_reference.obj_id = object_data.obj_id";
172
173 $res = $ilDB->query($query);
174 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
175
176 return $seas_ref_id = (int) $row->ref_id;
177 }
178
179 public function enabledLucene(): bool
180 {
181 return $this->lucene;
182 }
183 public function enableLucene(bool $a_status): void
184 {
185 $this->lucene = $a_status;
186 }
187
188 public function getMaxHits(): int
189 {
190 return $this->max_hits;
191 }
192 public function setMaxHits(int $a_max_hits): void
193 {
194 $this->max_hits = $a_max_hits;
195 }
196
197 public function getDefaultOperator(): int
198 {
200 }
201
202 public function setDefaultOperator(int $a_op): void
203 {
204 $this->default_operator = $a_op;
205 }
206
207 public function setFragmentSize(int $a_size): void
208 {
209 $this->fragmentSize = $a_size;
210 }
211
212 public function getFragmentSize(): int
213 {
214 return $this->fragmentSize;
215 }
216
217 public function setFragmentCount(int $a_count): void
218 {
219 $this->fragmentCount = $a_count;
220 }
221
222 public function getAutoCompleteLength(): int
223 {
225 }
227 {
228 $this->auto_complete_length = $auto_complete_length;
229 }
230
231 public function getFragmentCount(): int
232 {
234 }
235
236 public function setMaxSubitems(int $a_max): void
237 {
238 $this->numSubitems = $a_max;
239 }
240
241 public function getMaxSubitems(): int
242 {
243 return $this->numSubitems;
244 }
245
246 public function getLastIndexTime(): ilDateTime
247 {
248 return $this->last_index_date instanceof ilDateTime ?
249 $this->last_index_date :
250 new ilDateTime('2009-01-01 12:00:00', IL_CAL_DATETIME);
251 }
252
253 public function enableLuceneItemFilter(bool $a_status): void
254 {
255 $this->lucene_item_filter_enabled = $a_status;
256 }
257
258 public function isLuceneItemFilterEnabled(): bool
259 {
261 }
262
263 public function getLuceneItemFilter(): array
264 {
266 }
267
268
269 public function setLuceneItemFilter(array $a_filter): void
270 {
271 $this->lucene_item_filter = $a_filter;
272 }
273
274 public function enableLuceneOfflineFilter(bool $a_stat): void
275 {
276 $this->lucene_offline_filter = $a_stat;
277 }
278
279 public function isLuceneOfflineFilterEnabled(): bool
280 {
282 }
283
284 public function setLuceneMimeFilter(array $a_filter): void
285 {
286 $this->lucene_mime_filter = $a_filter;
287 }
288
289 public function getLuceneMimeFilter(): array
290 {
292 }
293
297 public function isLuceneMimeFilterEnabled(): bool
298 {
300 }
301
302 public function enableLuceneMimeFilter(bool $a_stat): void
303 {
304 $this->lucene_mime_filter_enabled = $a_stat;
305 }
306
307
308 public function setLastIndexTime(?ilDateTime $time): void
309 {
310 $this->last_index_date = $time;
311 }
312
316 public function isLuceneUserSearchEnabled(): bool
317 {
318 return $this->user_search;
319 }
320
321 public function enableLuceneUserSearch(bool $a_status): void
322 {
323 $this->user_search = $a_status;
324 }
325
329 public function showInactiveUser(bool $a_visible): void
330 {
331 $this->show_inactiv_user = $a_visible;
332 }
333
334 public function isInactiveUserVisible(): bool
335 {
337 }
338
342 public function showLimitedUser(bool $a_visible): void
343 {
344 $this->show_limited_user = $a_visible;
345 }
346
347
348 public function isLimitedUserVisible(): bool
349 {
351 }
352
353 public function isDateFilterEnabled(): bool
354 {
355 return $this->date_filter;
356 }
357
358 public function enableDateFilter(bool $a_filter): void
359 {
360 $this->date_filter = $a_filter;
361 }
362
363 public function update(): void
364 {
365 $this->setting->set('search_max_hits', (string) $this->getMaxHits());
366 $this->setting->set('search_lucene', (string) $this->enabledLucene());
367
368 $this->setting->set('lucene_default_operator', (string) $this->getDefaultOperator());
369 $this->setting->set('lucene_fragment_size', (string) $this->getFragmentSize());
370 $this->setting->set('lucene_fragment_count', (string) $this->getFragmentCount());
371 $this->setting->set('lucene_max_subitems', (string) $this->getMaxSubitems());
372 $this->setting->set('lucene_last_index_time', (string) $this->getLastIndexTime()->get(IL_CAL_UNIX));
373 $this->setting->set('auto_complete_length', (string) $this->getAutoCompleteLength());
374 $this->setting->set('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled());
375 $this->setting->set('lucene_item_filter', serialize($this->getLuceneItemFilter()));
376 $this->setting->set('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled());
377 $this->setting->set('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
378 $this->setting->set('lucene_mime_filter_enabled', (string) $this->isLuceneMimeFilterEnabled());
379 $this->setting->set('lucene_prefix_wildcard', (string) $this->isPrefixWildcardQueryEnabled());
380 $this->setting->set('lucene_user_search', (string) $this->isLuceneUserSearchEnabled());
381 $this->setting->set('search_show_inactiv_user', (string) $this->isInactiveUserVisible());
382 $this->setting->set('search_show_limited_user', (string) $this->isLimitedUserVisible());
383 $this->setting->set('search_date_filter', (string) $this->isDateFilterEnabled());
384 }
385
386 protected function __read()
387 {
388 $this->setMaxHits((int) $this->setting->get('search_max_hits', '10'));
389 $this->enableLucene((bool) $this->setting->get('search_lucene', '0'));
390 $this->setDefaultOperator((int) $this->setting->get('lucene_default_operator', (string) self::OPERATOR_AND));
391 $this->setFragmentSize((int) $this->setting->get('lucene_fragment_size', "50"));
392 $this->setFragmentCount((int) $this->setting->get('lucene_fragment_count', "3"));
393 $this->setMaxSubitems((int) $this->setting->get('lucene_max_subitems', "5"));
394 if ($time = $this->setting->get('lucene_last_index_time', '0')) {
395 $this->setLastIndexTime(new ilDateTime($time, IL_CAL_UNIX));
396 } else {
397 $this->setLastIndexTime(null);
398 }
399 $this->setAutoCompleteLength((int) $this->setting->get('auto_complete_length', (string) $this->getAutoCompleteLength()));
400 $this->enableLuceneItemFilter((bool) $this->setting->get('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled()));
401 $filter = (string) $this->setting->get('lucene_item_filter', serialize($this->getLuceneItemFilter()));
402 $this->setLuceneItemFilter(unserialize($filter));
403 $this->enableLuceneOfflineFilter((bool) $this->setting->get('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled()));
404 $this->enableLuceneMimeFilter((bool) $this->setting->get('lucene_mime_filter_enabled', (string) $this->lucene_item_filter_enabled));
405 $filter = (string) $this->setting->get('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
406 $this->setLuceneMimeFilter(unserialize($filter));
407 $this->enablePrefixWildcardQuery((bool) $this->setting->get('lucene_prefix_wildcard', (string) $this->prefix_wildcard));
408 $this->enableLuceneUserSearch((bool) $this->setting->get('lucene_user_search', (string) $this->user_search));
409 $this->showInactiveUser((bool) $this->setting->get('search_show_inactiv_user', (string) $this->show_inactiv_user));
410 $this->showLimitedUser((bool) $this->setting->get('search_show_limited_user', (string) $this->show_limited_user));
411 $this->enableDateFilter((bool) $this->setting->get('search_date_filter', (string) $this->date_filter));
412 }
413}
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)
enableLuceneUserSearch(bool $a_status)
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)
setLuceneItemFilter(array $a_filter)
setLastIndexTime(?ilDateTime $time)
enableLuceneMimeFilter(bool $a_stat)
getEnabledLuceneItemFilterDefinitions()
Get lucene item filter definitions.
enableLuceneItemFilter(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
ILIAS Setting Class.
const SYSTEM_FOLDER_ID
Definition: constants.php:35
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26