ILIAS  trunk Revision v12.0_alpha-399-g579a087ced2
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 ?ilDateTime $last_index_date = null;
38 protected bool $lucene_item_filter_enabled = false;
39 protected array $lucene_item_filter = array();
40 protected bool $lucene_offline_filter = true;
41 protected int $auto_complete_length = 10;
42 protected bool $show_inactiv_user = true;
43 protected bool $show_limited_user = true;
44
45 protected bool $lucene = false;
46 protected bool $lucene_mime_filter_enabled = false;
47 protected array $lucene_mime_filter = array();
48 protected bool $prefix_wildcard = false;
49 protected bool $user_search = false;
50 protected bool $date_filter = false;
51
52 protected ?ILIAS $ilias = null;
54 private int $max_hits = 10;
55
56 public function __construct()
57 {
58 global $DIC;
59
60 $this->ilias = $DIC['ilias'];
61 $this->setting = $DIC->settings();
62 $this->__read();
63 }
64
65 public static function getInstance(): ilSearchSettings
66 {
67 if (self::$instance instanceof ilSearchSettings) {
68 return self::$instance;
69 }
70 return self::$instance = new ilSearchSettings();
71 }
72
77 public static function getLuceneItemFilterDefinitions(): array
78 {
79 return array(
80 'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
81 'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
82 'lms' => array('filter' => 'type:lm OR type:htlm','trans' => 'obj_lrss'),
83 'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
84 'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
85 'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
86 'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
87 'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
88 'file' => array('filter' => 'type:file','trans' => 'objs_file'),
89 'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
90 'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki'),
91 'copa' => array('filter' => 'type:copa','trans' => 'objs_copa'),
92 );
93 }
94
95 public static function getLuceneMimeFilterDefinitions(): array
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
111 {
112 if (!$this->isLuceneItemFilterEnabled()) {
113 return array();
114 }
115
116 $filter = $this->getLuceneItemFilter();
117 $enabled = array();
118 foreach (self::getLuceneItemFilterDefinitions() as $obj => $def) {
119 if (isset($filter[$obj]) and $filter[$obj]) {
120 $enabled[$obj] = $def;
121 }
122 }
123 return $enabled;
124 }
125
127 {
128 if (!$this->isLuceneMimeFilterEnabled()) {
129 return array();
130 }
131
132 $filter = $this->getLuceneMimeFilter();
133 $enabled = array();
134 foreach (self::getLuceneMimeFilterDefinitions() as $mime => $def) {
135 if (isset($filter[$mime]) and $filter[$mime]) {
136 $enabled[$mime] = $def;
137 }
138 }
139 return $enabled;
140 }
141
142 public function enablePrefixWildcardQuery(bool $a_stat): void
143 {
144 $this->prefix_wildcard = $a_stat;
145 }
146
147 public function isPrefixWildcardQueryEnabled(): bool
148 {
150 }
151
155 public static function _getSearchSettingRefId(): int
156 {
157 global $DIC;
158
159 $ilDB = $DIC->database();
160
161 static $seas_ref_id = 0;
162
163 if ($seas_ref_id) {
164 return $seas_ref_id;
165 }
166 $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data " .
167 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
168 "AND object_data.type = 'seas' " .
169 "AND object_reference.ref_id = tree.child " .
170 "AND object_reference.obj_id = object_data.obj_id";
171
172 $res = $ilDB->query($query);
173 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
174
175 return $seas_ref_id = (int) $row->ref_id;
176 }
177
178 public function enabledLucene(): bool
179 {
180 return $this->lucene;
181 }
182 public function enableLucene(bool $a_status): void
183 {
184 $this->lucene = $a_status;
185 }
186
187 public function getMaxHits(): int
188 {
189 return $this->max_hits;
190 }
191 public function setMaxHits(int $a_max_hits): void
192 {
193 $this->max_hits = $a_max_hits;
194 }
195
196 public function getDefaultOperator(): int
197 {
199 }
200
201 public function setDefaultOperator(int $a_op): void
202 {
203 $this->default_operator = $a_op;
204 }
205
206 public function setFragmentSize(int $a_size): void
207 {
208 $this->fragmentSize = $a_size;
209 }
210
211 public function getFragmentSize(): int
212 {
213 return $this->fragmentSize;
214 }
215
216 public function setFragmentCount(int $a_count): void
217 {
218 $this->fragmentCount = $a_count;
219 }
220
221 public function getAutoCompleteLength(): int
222 {
224 }
226 {
227 $this->auto_complete_length = $auto_complete_length;
228 }
229
230 public function getFragmentCount(): int
231 {
233 }
234
235 public function getLastIndexTime(): ilDateTime
236 {
237 return $this->last_index_date instanceof ilDateTime ?
238 $this->last_index_date :
239 new ilDateTime('2009-01-01 12:00:00', IL_CAL_DATETIME);
240 }
241
242 public function enableLuceneItemFilter(bool $a_status): void
243 {
244 $this->lucene_item_filter_enabled = $a_status;
245 }
246
247 public function isLuceneItemFilterEnabled(): bool
248 {
250 }
251
252 public function getLuceneItemFilter(): array
253 {
255 }
256
257
258 public function setLuceneItemFilter(array $a_filter): void
259 {
260 $this->lucene_item_filter = $a_filter;
261 }
262
263 public function enableLuceneOfflineFilter(bool $a_stat): void
264 {
265 $this->lucene_offline_filter = $a_stat;
266 }
267
268 public function isLuceneOfflineFilterEnabled(): bool
269 {
271 }
272
273 public function setLuceneMimeFilter(array $a_filter): void
274 {
275 $this->lucene_mime_filter = $a_filter;
276 }
277
278 public function getLuceneMimeFilter(): array
279 {
281 }
282
286 public function isLuceneMimeFilterEnabled(): bool
287 {
289 }
290
291 public function enableLuceneMimeFilter(bool $a_stat): void
292 {
293 $this->lucene_mime_filter_enabled = $a_stat;
294 }
295
296
297 public function setLastIndexTime(?ilDateTime $time): void
298 {
299 $this->last_index_date = $time;
300 }
301
305 public function isLuceneUserSearchEnabled(): bool
306 {
307 return $this->user_search;
308 }
309
310 public function enableLuceneUserSearch(bool $a_status): void
311 {
312 $this->user_search = $a_status;
313 }
314
318 public function showInactiveUser(bool $a_visible): void
319 {
320 $this->show_inactiv_user = $a_visible;
321 }
322
323 public function isInactiveUserVisible(): bool
324 {
326 }
327
331 public function showLimitedUser(bool $a_visible): void
332 {
333 $this->show_limited_user = $a_visible;
334 }
335
336
337 public function isLimitedUserVisible(): bool
338 {
340 }
341
342 public function isDateFilterEnabled(): bool
343 {
344 return $this->date_filter;
345 }
346
347 public function enableDateFilter(bool $a_filter): void
348 {
349 $this->date_filter = $a_filter;
350 }
351
352 public function update(): void
353 {
354 $this->setting->set('search_max_hits', (string) $this->getMaxHits());
355 $this->setting->set('search_lucene', (string) $this->enabledLucene());
356
357 $this->setting->set('lucene_default_operator', (string) $this->getDefaultOperator());
358 $this->setting->set('lucene_fragment_size', (string) $this->getFragmentSize());
359 $this->setting->set('lucene_fragment_count', (string) $this->getFragmentCount());
360 $this->setting->set('lucene_last_index_time', (string) $this->getLastIndexTime()->get(IL_CAL_UNIX));
361 $this->setting->set('auto_complete_length', (string) $this->getAutoCompleteLength());
362 $this->setting->set('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled());
363 $this->setting->set('lucene_item_filter', serialize($this->getLuceneItemFilter()));
364 $this->setting->set('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled());
365 $this->setting->set('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
366 $this->setting->set('lucene_mime_filter_enabled', (string) $this->isLuceneMimeFilterEnabled());
367 $this->setting->set('lucene_prefix_wildcard', (string) $this->isPrefixWildcardQueryEnabled());
368 $this->setting->set('lucene_user_search', (string) $this->isLuceneUserSearchEnabled());
369 $this->setting->set('search_show_inactiv_user', (string) $this->isInactiveUserVisible());
370 $this->setting->set('search_show_limited_user', (string) $this->isLimitedUserVisible());
371 $this->setting->set('search_date_filter', (string) $this->isDateFilterEnabled());
372 }
373
374 protected function __read()
375 {
376 $this->setMaxHits((int) $this->setting->get('search_max_hits', '10'));
377 $this->enableLucene((bool) $this->setting->get('search_lucene', '0'));
378 $this->setDefaultOperator((int) $this->setting->get('lucene_default_operator', (string) self::OPERATOR_AND));
379 $this->setFragmentSize((int) $this->setting->get('lucene_fragment_size', "50"));
380 $this->setFragmentCount((int) $this->setting->get('lucene_fragment_count', "3"));
381 if ($time = $this->setting->get('lucene_last_index_time', '0')) {
382 $this->setLastIndexTime(new ilDateTime($time, IL_CAL_UNIX));
383 } else {
384 $this->setLastIndexTime(null);
385 }
386 $this->setAutoCompleteLength((int) $this->setting->get('auto_complete_length', (string) $this->getAutoCompleteLength()));
387 $this->enableLuceneItemFilter((bool) $this->setting->get('lucene_item_filter_enabled', (string) $this->isLuceneItemFilterEnabled()));
388 $filter = (string) $this->setting->get('lucene_item_filter', serialize($this->getLuceneItemFilter()));
389 $this->setLuceneItemFilter(unserialize($filter));
390 $this->enableLuceneOfflineFilter((bool) $this->setting->get('lucene_offline_filter', (string) $this->isLuceneOfflineFilterEnabled()));
391 $this->enableLuceneMimeFilter((bool) $this->setting->get('lucene_mime_filter_enabled', (string) $this->lucene_item_filter_enabled));
392 $filter = (string) $this->setting->get('lucene_mime_filter', serialize($this->getLuceneMimeFilter()));
393 $this->setLuceneMimeFilter(unserialize($filter));
394 $this->enablePrefixWildcardQuery((bool) $this->setting->get('lucene_prefix_wildcard', (string) $this->prefix_wildcard));
395 $this->enableLuceneUserSearch((bool) $this->setting->get('lucene_user_search', (string) $this->user_search));
396 $this->showInactiveUser((bool) $this->setting->get('search_show_inactiv_user', (string) $this->show_inactiv_user));
397 $this->showLimitedUser((bool) $this->setting->get('search_show_limited_user', (string) $this->show_limited_user));
398 $this->enableDateFilter((bool) $this->setting->get('search_date_filter', (string) $this->date_filter));
399 }
400}
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