ILIAS  release_7 Revision v7.30-3-g800a261c036
ilSearch Class Reference

search More...

+ Collaboration diagram for ilSearch:

Public Member Functions

 __construct ($a_user_id=0, $a_read=false)
 Constructor @access public. More...
 
 setSearchString ($a_search_str)
 
 setCombination ($a_combination)
 
 setSearchFor ($a_search_for)
 
 setSearchIn ($a_search_in)
 
 setResult ($a_result)
 
 setSearchType ($a_type)
 
 setPerformUpdate ($a_value)
 
 setEmptySearch ($a_value)
 
 setMinWordLength ($a_min_word_length)
 
 getMinWordLength ()
 
 getUserId ()
 
 getSearchString ()
 
 getCombination ()
 
 getSearchFor ()
 
 getSearchIn ()
 
 getSearchInByType ($a_type)
 
 getResults ()
 
 getResultByType ($a_type)
 
 getSearchType ()
 
 getPerformUpdate ()
 
 getEmptySearch ()
 
 getNumberOfResults ()
 
 validate (&$message)
 
 performSearch ()
 
 __parseSearchString ()
 
 __updateDBResult ()
 
 __readDBResult ()
 
 __checkAccess ($a_results, $a_type)
 
 __validateResults ()
 
 __prepareWord ($a_word)
 

Data Fields

 $ilias
 
 $lng
 
 $rbacsystem
 
 $user_id
 
 $search_string
 
 $parsed_str
 
 $combination
 
 $min_word_length = 3
 
 $search_for
 
 $search_in
 
 $search_type
 
 $result
 
 $perform_update
 
 $read_db_result
 
 $allow_empty_search
 

Protected Member Functions

 performUserSearch ()
 perform a search for users More...
 
 performObjectSearch ($a_type)
 perform object search More...
 
 performRoleSearch ()
 
 initQueryParser ()
 init query parser More...
 

Protected Attributes

 $qp = null
 

Detailed Description

search

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id$

Definition at line 14 of file class.ilSearch.php.

Constructor & Destructor Documentation

◆ __construct()

ilSearch::__construct (   $a_user_id = 0,
  $a_read = false 
)

Constructor @access public.

Definition at line 43 of file class.ilSearch.php.

44 {
45 global $DIC;
46
47 $ilias = $DIC['ilias'];
48 $rbacsystem = $DIC['rbacsystem'];
49 $lng = $DIC['lng'];
50
51 // Initiate variables
52 $this->ilias = &$ilias;
53 $this->lng = &$lng;
54 $this->lng->loadLanguageModule("search");
55 $this->rbacsystem = &$rbacsystem;
56 $this->user_id = $a_user_id;
57
58 $this->setPerformUpdate(true);
59 $this->setEmptySearch(false);
60 $this->read_db_result = $a_read;
61
62 // READ OLD SEARCH RESULTS FROM DATABASE
63 #$this->__readDBResult();
64 }
setEmptySearch($a_value)
setPerformUpdate($a_value)
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file)

References $DIC, $ilias, $lng, $rbacsystem, setEmptySearch(), and setPerformUpdate().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkAccess()

ilSearch::__checkAccess (   $a_results,
  $a_type 
)

Definition at line 340 of file class.ilSearch.php.

341 {
342 global $DIC;
343
344 $ilAccess = $DIC['ilAccess'];
345
346 if (is_array($a_results)) {
347 foreach ($a_results as $result) {
348 if ($ilAccess->checkAccess('read', '', $result['id'])) {
349 $checked_result[] = $result;
350 break;
351 }
352 }
353 }
354 return $checked_result ? $checked_result : array();
355 }

References $DIC, and $result.

Referenced by __validateResults().

+ Here is the caller graph for this function:

◆ __parseSearchString()

ilSearch::__parseSearchString ( )

Definition at line 242 of file class.ilSearch.php.

243 {
244 $tmp_arr = explode(" ", $this->getSearchString());
245 $this->parsed_str["and"] = $this->parsed_str["or"] = $this->parsed_str["not"] = array();
246
247 foreach ($tmp_arr as $word) {
248 #$word = trim($word);
249 $word = $this->__prepareWord($word);
250 if ($word) {
251 if (substr($word, 0, 1) == '+') {
252 $this->parsed_str["all"][] = substr($word, 1);
253 $this->parsed_str["and"][] = substr($word, 1);
254 continue;
255 }
256
257 if (substr($word, 0, 1) == '-') {
258 // better parsed_str["allmost_all"] ;-)
259 #$this->parsed_str["all"][] = substr($word,1);
260 $this->parsed_str["not"][] = substr($word, 1);
261 continue;
262 }
263
264 if ($this->getCombination() == 'and') {
265 $this->parsed_str["all"][] = $word;
266 $this->parsed_str["and"][] = $word;
267 continue;
268 }
269
270 if ($this->getCombination() == 'or') {
271 $this->parsed_str["all"][] = $word;
272 $this->parsed_str["or"][] = $word;
273 continue;
274 }
275 }
276 }
277 }
__prepareWord($a_word)

References __prepareWord(), getCombination(), and getSearchString().

+ Here is the call graph for this function:

◆ __prepareWord()

ilSearch::__prepareWord (   $a_word)

Definition at line 428 of file class.ilSearch.php.

429 {
430 $word = trim($a_word);
431
432 if (!preg_match('/\*/', $word)) {
433 return '%' . $word . '%';
434 }
435 if (preg_match('/^\*/', $word)) {
436 return str_replace('*', '%', $word);
437 } else {
438 return '% ' . str_replace('*', '%', $word);
439 }
440 }

Referenced by __parseSearchString().

+ Here is the caller graph for this function:

◆ __readDBResult()

ilSearch::__readDBResult ( )

Definition at line 306 of file class.ilSearch.php.

307 {
308 global $DIC;
309
310 $ilDB = $DIC['ilDB'];
311
312 if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID and $this->read_db_result) {
313 $query = "SELECT search_result FROM usr_search " .
314 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer');
315
316
317 $res = $ilDB->query($query);
318 if ($res->numRows()) {
319 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
320 $this->setResult(unserialize(stripslashes($row->search_result)));
321 } else {
322 $this->setResult(array("usr" => array(),
323 "grp" => array(),
324 "lm" => array(),
325 "dbk" => array()));
326 }
327 } else {
328 $this->setResult(array("usr" => array(),
329 "grp" => array(),
330 "lm" => array(),
331 "dbk" => array()));
332 }
333
334 $this->__validateResults();
335 $this->__updateDBResult();
336 return true;
337 }
setResult($a_result)
const ANONYMOUS_USER_ID
Definition: constants.php:25
$query
foreach($_POST as $key=> $value) $res
global $ilDB

References $DIC, $ilDB, $query, $res, __updateDBResult(), __validateResults(), ANONYMOUS_USER_ID, ilDBConstants\FETCHMODE_OBJECT, getUserId(), and setResult().

+ Here is the call graph for this function:

◆ __updateDBResult()

ilSearch::__updateDBResult ( )

Definition at line 279 of file class.ilSearch.php.

280 {
281 global $DIC;
282
283 $ilDB = $DIC['ilDB'];
284
285 if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID) {
286 $ilDB->manipulate("DELETE FROM usr_search " .
287 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
288 "AND search_type = 0 ");
289
290 $ilDB->insert('usr_search', array(
291 'usr_id' => array('integer',$this->getUserId()),
292 'search_result' => array('clob',serialize($this->getResults())),
293 'checked' => array('clob',serialize(array())),
294 'failed' => array('clob',serialize(array())),
295 'page' => array('integer',0),
296 'search_type' => array('integer',0),
297 'query' => array('text',''),
298 'root' => array('integer',ROOT_FOLDER_ID)));
299
300 return true;
301 }
302
303 return false;
304 }
const ROOT_FOLDER_ID
Definition: constants.php:30

References $DIC, $ilDB, ANONYMOUS_USER_ID, getResults(), getUserId(), and ROOT_FOLDER_ID.

Referenced by __readDBResult(), and performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __validateResults()

ilSearch::__validateResults ( )

Definition at line 358 of file class.ilSearch.php.

359 {
360 global $DIC;
361
362 $tree = $DIC['tree'];
363
364 $new_result = array();
365
366
367 // check lm meta
368
369 $this->result['lm']['meta'] = $this->__checkAccess($this->result['lm']['meta'], 'lm');
370 if (is_array($this->result['lm']['meta'])) {
371 foreach ($this->result['lm']['meta'] as $data) {
372 if ($tree->isInTree($data['id'])) {
373 $new_result['lm']['meta'][] = $data;
374 }
375 }
376 }
377 $this->result['lm']['content'] = $this->__checkAccess($this->result['lm']['content'], 'lm');
378 if (is_array($this->result['lm']['content'])) {
379 foreach ($this->result['lm']['content'] as $data) {
380 if ($tree->isInTree($data['id'])) {
381 $new_result['lm']['content'][] = $data;
382 }
383 }
384 }
385 $this->result['dbk']['meta'] = $this->__checkAccess($this->result['dbk']['meta'], 'dbk');
386 if (is_array($this->result['dbk']['meta'])) {
387 foreach ($this->result['dbk']['meta'] as $data) {
388 if ($tree->isInTree($data['id'])) {
389 $new_result['dbk']['meta'][] = $data;
390 }
391 }
392 }
393 $this->result['dbk']['content'] = $this->__checkAccess($this->result['dbk']['content'], 'dbk');
394 if (is_array($this->result['dbk']['content'])) {
395 foreach ($this->result['dbk']['content'] as $data) {
396 if ($tree->isInTree($data['id'])) {
397 $new_result['dbk']['content'][] = $data;
398 }
399 }
400 }
401 $this->result['grp'] = $this->__checkAccess($this->result['grp'], 'grp');
402 if (is_array($this->result['grp'])) {
403 foreach ($this->result['grp'] as $data) {
404 if ($tree->isInTree($data['id'])) {
405 $new_result['grp'][] = $data;
406 }
407 }
408 }
409 if (is_array($this->result['usr'])) {
410 foreach ($this->result['usr'] as $user) {
411 if ($tmp_obj = &ilObjectFactory::getInstanceByObjId($user['id'], false)) {
412 $new_result['usr'][] = $user;
413 }
414 }
415 }
416 if (is_array($this->result['role'])) {
417 foreach ($this->result['role'] as $user) {
418 if ($tmp_obj = &ilObjectFactory::getInstanceByObjId($user['id'], false)) {
419 $new_result['role'][] = $user;
420 }
421 }
422 }
423 $this->setResult($new_result);
424
425 return true;
426 }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
__checkAccess($a_results, $a_type)
$data
Definition: storeScorm.php:23

References $data, $DIC, __checkAccess(), ilObjectFactory\getInstanceByObjId(), and setResult().

Referenced by __readDBResult(), and performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCombination()

ilSearch::getCombination ( )

Definition at line 119 of file class.ilSearch.php.

120 {
121 return $this->combination ? $this->combination : "or";
122 }

Referenced by __parseSearchString(), initQueryParser(), and performObjectSearch().

+ Here is the caller graph for this function:

◆ getEmptySearch()

ilSearch::getEmptySearch ( )

Definition at line 155 of file class.ilSearch.php.

156 {
158 }

References $allow_empty_search.

◆ getMinWordLength()

ilSearch::getMinWordLength ( )

Definition at line 105 of file class.ilSearch.php.

106 {
108 }

References $min_word_length.

Referenced by initQueryParser().

+ Here is the caller graph for this function:

◆ getNumberOfResults()

ilSearch::getNumberOfResults ( )

Definition at line 162 of file class.ilSearch.php.

163 {
164 $number = count($this->getResultByType("usr")) + count($this->getResultByType("grp")) + count($this->getResultByType("role"));
165
166 $tmp_res = $this->getResultByType("dbk");
167 $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
168
169 $tmp_res = $this->getResultByType("lm");
170 $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
171
172 return $number;
173 }
getResultByType($a_type)

References getResultByType().

+ Here is the call graph for this function:

◆ getPerformUpdate()

ilSearch::getPerformUpdate ( )

Definition at line 151 of file class.ilSearch.php.

152 {
154 }

References $perform_update.

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ getResultByType()

ilSearch::getResultByType (   $a_type)

Definition at line 143 of file class.ilSearch.php.

144 {
145 return $this->result[$a_type] ? $this->result[$a_type] : array();
146 }

Referenced by getNumberOfResults().

+ Here is the caller graph for this function:

◆ getResults()

ilSearch::getResults ( )

Definition at line 139 of file class.ilSearch.php.

140 {
141 return $this->result ? $this->result : array();
142 }

Referenced by __updateDBResult().

+ Here is the caller graph for this function:

◆ getSearchFor()

ilSearch::getSearchFor ( )

Definition at line 123 of file class.ilSearch.php.

124 {
125 return $this->search_for ? $this->search_for : array();
126 }

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ getSearchIn()

ilSearch::getSearchIn ( )

Definition at line 127 of file class.ilSearch.php.

128 {
129 return $this->search_in ? $this->search_in : array();
130 }

◆ getSearchInByType()

ilSearch::getSearchInByType (   $a_type)

Definition at line 131 of file class.ilSearch.php.

132 {
133 if ($a_type == 'lm' or $a_type == 'dbk') {
134 return $this->search_in[$a_type];
135 } else {
136 return false;
137 }
138 }

◆ getSearchString()

ilSearch::getSearchString ( )

Definition at line 115 of file class.ilSearch.php.

116 {
118 }

References $search_string.

Referenced by __parseSearchString(), and initQueryParser().

+ Here is the caller graph for this function:

◆ getSearchType()

ilSearch::getSearchType ( )

Definition at line 147 of file class.ilSearch.php.

148 {
149 return $this->search_type;
150 }

References $search_type.

◆ getUserId()

ilSearch::getUserId ( )

Definition at line 111 of file class.ilSearch.php.

112 {
113 return $this->user_id;
114 }

References $user_id.

Referenced by __readDBResult(), __updateDBResult(), and performUserSearch().

+ Here is the caller graph for this function:

◆ initQueryParser()

ilSearch::initQueryParser ( )
protected

init query parser

Returns

Definition at line 511 of file class.ilSearch.php.

512 {
513 if ($this->qp) {
514 return true;
515 }
516
517 $this->qp = new ilQueryParser($this->getSearchString());
518 $this->qp->setCombination($this->getCombination() == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
519 $this->qp->setMinWordLength($this->getMinWordLength());
520 $this->qp->parse();
521 }
const QP_COMBINATION_OR
const QP_COMBINATION_AND
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References getCombination(), getMinWordLength(), getSearchString(), QP_COMBINATION_AND, and QP_COMBINATION_OR.

Referenced by performSearch(), and validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performObjectSearch()

ilSearch::performObjectSearch (   $a_type)
protected

perform object search

Returns

Definition at line 472 of file class.ilSearch.php.

473 {
474 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
475 $object_search = new ilLikeObjectSearch($this->qp);
476 $object_search->setFilter(array($a_type));
477 $res = $object_search->performSearch();
478 $res->filter(ROOT_FOLDER_ID, $this->getCombination());
479
480 $counter = 0;
481 foreach ($res->getResultIds() as $id) {
482 $objs[$counter++]['id'] = $id;
483 }
484 return $objs ? $objs : array();
485 }

References $res, getCombination(), and ROOT_FOLDER_ID.

Referenced by performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performRoleSearch()

ilSearch::performRoleSearch ( )
protected
Parameters

return

Definition at line 492 of file class.ilSearch.php.

493 {
494 // Perform like search
495 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
496 $object_search = new ilLikeObjectSearch($this->qp);
497 $object_search->setFilter(array('role'));
498
499 $res = $object_search->performSearch();
500 foreach ($res->getEntries() as $id => $data) {
501 $tmp['id'] = $id;
502 $roles[] = $tmp;
503 }
504 return $roles ? $roles : array();
505 }

References $data, and $res.

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ performSearch()

ilSearch::performSearch ( )

Definition at line 186 of file class.ilSearch.php.

187 {
188 global $DIC;
189
190 $objDefinition = $DIC['objDefinition'];
191 $ilBench = $DIC['ilBench'];
192
193 $ilBench->start("Search", "performSearch");
194
195 $this->initQueryParser();
196
197 $result = array("usr" => array(),
198 "grp" => array(),
199 "lm" => array(),
200 "dbk" => array(),
201 "role" => array());
202
203 foreach ($this->getSearchFor() as $obj_type) {
204 switch ($obj_type) {
205 case "usr":
206 $result['usr'] = $this->performUserSearch();
207 break;
208
209 case "grp":
210 $result['grp'] = $this->performObjectSearch('grp');
211 break;
212
213 case "lm":
214 $result['lm'] = $this->performObjectSearch('lm');
215 break;
216
217 case "dbk":
218 $result['dbk'] = $this->performObjectSearch('dbk');
219 break;
220
221 case "role":
222 $result['role'] = $this->performRoleSearch();
223 break;
224 }
225 }
226
227 $this->setResult($result);
228 $this->__validateResults();
229
230 if ($this->getPerformUpdate()) {
231 $this->__updateDBResult();
232 }
233
234 $ilBench->stop("Search", "performSearch");
235
236 return true;
237 }
initQueryParser()
init query parser
performObjectSearch($a_type)
perform object search
performUserSearch()
perform a search for users
global $ilBench
Definition: ilias.php:21

References $DIC, $ilBench, $result, __updateDBResult(), __validateResults(), getPerformUpdate(), getSearchFor(), initQueryParser(), performObjectSearch(), performRoleSearch(), performUserSearch(), and setResult().

+ Here is the call graph for this function:

◆ performUserSearch()

ilSearch::performUserSearch ( )
protected

perform a search for users

Returns

Definition at line 446 of file class.ilSearch.php.

447 {
448 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
449
450 $user_search = ilObjectSearchFactory::_getUserSearchInstance($this->qp);
451 $res = new ilSearchResult($this->getUserId());
452
453 foreach (array("login","firstname","lastname","title",
454 "email","institution","street","city","zipcode","country","phone_home","fax") as $field) {
455 $user_search->setFields(array($field));
456 $tmp_res = $user_search->performSearch();
457
458 $res->mergeEntries($tmp_res);
459 }
460
461 foreach ($res->getEntries() as $id => $data) {
462 $tmp['id'] = $id;
463 $users[] = $tmp;
464 }
465 return $users ? $users : array();
466 }
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch

References $data, $res, ilObjectSearchFactory\_getUserSearchInstance(), and getUserId().

Referenced by performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCombination()

ilSearch::setCombination (   $a_combination)

Definition at line 71 of file class.ilSearch.php.

72 {
73 // 'and' or 'or'
74 $this->combination = $a_combination;
75 }

◆ setEmptySearch()

ilSearch::setEmptySearch (   $a_value)

Definition at line 96 of file class.ilSearch.php.

97 {
98 $this->allow_empty_search = $a_value;
99 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setMinWordLength()

ilSearch::setMinWordLength (   $a_min_word_length)

Definition at line 101 of file class.ilSearch.php.

102 {
103 $this->min_word_length = $a_min_word_length;
104 }

◆ setPerformUpdate()

ilSearch::setPerformUpdate (   $a_value)

Definition at line 92 of file class.ilSearch.php.

93 {
94 $this->perform_update = $a_value;
95 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setResult()

ilSearch::setResult (   $a_result)

Definition at line 84 of file class.ilSearch.php.

85 {
86 $this->result = $a_result;
87 }

Referenced by __readDBResult(), __validateResults(), and performSearch().

+ Here is the caller graph for this function:

◆ setSearchFor()

ilSearch::setSearchFor (   $a_search_for)

Definition at line 76 of file class.ilSearch.php.

77 {
78 $this->search_for = $a_search_for;
79 }

◆ setSearchIn()

ilSearch::setSearchIn (   $a_search_in)

Definition at line 80 of file class.ilSearch.php.

81 {
82 $this->search_in = $a_search_in;
83 }

◆ setSearchString()

ilSearch::setSearchString (   $a_search_str)

Definition at line 67 of file class.ilSearch.php.

68 {
69 $this->search_string = trim($a_search_str);
70 }

◆ setSearchType()

ilSearch::setSearchType (   $a_type)

Definition at line 88 of file class.ilSearch.php.

89 {
90 $this->search_type = $a_type;
91 }

◆ validate()

ilSearch::validate ( $message)

Definition at line 175 of file class.ilSearch.php.

176 {
177 $this->initQueryParser();
178
179 if (!$this->qp->validate()) {
180 $message = $this->qp->getMessage();
181 return false;
182 }
183 return true;
184 }
$message
Definition: xapiexit.php:14

References $message, and initQueryParser().

+ Here is the call graph for this function:

Field Documentation

◆ $allow_empty_search

ilSearch::$allow_empty_search

Definition at line 38 of file class.ilSearch.php.

Referenced by getEmptySearch().

◆ $combination

ilSearch::$combination

Definition at line 29 of file class.ilSearch.php.

◆ $ilias

ilSearch::$ilias

Definition at line 23 of file class.ilSearch.php.

Referenced by __construct().

◆ $lng

ilSearch::$lng

Definition at line 24 of file class.ilSearch.php.

Referenced by __construct().

◆ $min_word_length

ilSearch::$min_word_length = 3

Definition at line 30 of file class.ilSearch.php.

Referenced by getMinWordLength().

◆ $parsed_str

ilSearch::$parsed_str

Definition at line 28 of file class.ilSearch.php.

◆ $perform_update

ilSearch::$perform_update

Definition at line 35 of file class.ilSearch.php.

Referenced by getPerformUpdate().

◆ $qp

ilSearch::$qp = null
protected

Definition at line 16 of file class.ilSearch.php.

◆ $rbacsystem

ilSearch::$rbacsystem

Definition at line 25 of file class.ilSearch.php.

Referenced by __construct().

◆ $read_db_result

ilSearch::$read_db_result

Definition at line 36 of file class.ilSearch.php.

◆ $result

ilSearch::$result

Definition at line 34 of file class.ilSearch.php.

Referenced by __checkAccess(), and performSearch().

◆ $search_for

ilSearch::$search_for

Definition at line 31 of file class.ilSearch.php.

◆ $search_in

ilSearch::$search_in

Definition at line 32 of file class.ilSearch.php.

◆ $search_string

ilSearch::$search_string

Definition at line 27 of file class.ilSearch.php.

Referenced by getSearchString().

◆ $search_type

ilSearch::$search_type

Definition at line 33 of file class.ilSearch.php.

Referenced by getSearchType().

◆ $user_id

ilSearch::$user_id

Definition at line 26 of file class.ilSearch.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: