5 include_once
'./Services/Search/classes/class.ilQueryParser.php';
43 function ilSearch($a_user_id = 0,$a_read =
false)
50 $this->lng->loadLanguageModule(
"search");
52 $this->user_id = $a_user_id;
56 $this->read_db_result = $a_read;
59 #$this->__readDBResult();
65 $this->search_string = trim($a_search_str);
70 $this->combination = $a_combination;
74 $this->search_for = $a_search_for;
78 $this->search_in = $a_search_in;
82 $this->result = $a_result;
86 $this->search_type = $a_type;
90 $this->perform_update = $a_value;
94 $this->allow_empty_search = $a_value;
99 $this->min_word_length = $a_min_word_length;
117 return $this->combination ? $this->combination :
"or";
121 return $this->search_for ? $this->search_for : array();
125 return $this->search_in ? $this->search_in : array();
129 if($a_type ==
'lm' or $a_type ==
'dbk')
131 return $this->search_in[$a_type];
140 return $this->result ? $this->result : array();
144 return $this->result[$a_type] ? $this->result[$a_type] : array();
166 $number += count($tmp_res[
"meta"]) + count($tmp_res[
"content"]);
169 $number += count($tmp_res[
"meta"]) + count($tmp_res[
"content"]);
178 if(!$this->qp->validate())
180 $message = $this->qp->getMessage();
190 $ilBench->start(
"Search",
"performSearch");
194 $result = array(
"usr" => array(),
234 $ilBench->stop(
"Search",
"performSearch");
245 $this->parsed_str[
"and"] = $this->parsed_str[
"or"] = $this->parsed_str[
"not"] = array();
247 foreach ($tmp_arr as $word)
249 #$word = trim($word);
253 if (substr($word,0,1) ==
'+')
255 $this->parsed_str[
"all"][] = substr($word,1);
256 $this->parsed_str[
"and"][] = substr($word,1);
260 if (substr($word,0,1) ==
'-')
263 #$this->parsed_str["all"][] = substr($word,1);
264 $this->parsed_str[
"not"][] = substr($word,1);
270 $this->parsed_str[
"all"][] = $word;
271 $this->parsed_str[
"and"][] = $word;
277 $this->parsed_str[
"all"][] = $word;
278 $this->parsed_str[
"or"][] = $word;
291 $ilDB->manipulate(
"DELETE FROM usr_search ".
292 "WHERE usr_id = ".$ilDB->quote($this->getUserId() ,
'integer').
" ".
293 "AND search_type = 0 ");
295 $ilDB->insert(
'usr_search',array(
296 'usr_id' => array(
'integer',$this->
getUserId()),
297 'search_result' => array(
'clob',serialize($this->
getResults())),
298 'checked' => array(
'clob',serialize(array())),
299 'failed' => array(
'clob',serialize(array())),
300 'page' => array(
'integer',0),
301 'search_type' => array(
'integer',0),
302 'query' => array(
'text',
''),
303 'root' => array(
'integer',ROOT_FOLDER_ID)));
315 if ($this->
getUserId() != 0 and $this->
getUserId() != ANONYMOUS_USER_ID and $this->read_db_result)
317 $query =
"SELECT search_result FROM usr_search ".
318 "WHERE usr_id = ".$ilDB->quote($this->
getUserId() ,
'integer');
325 $this->
setResult(unserialize(stripslashes(
$row->search_result)));
353 if (is_array($a_results))
355 foreach ($a_results as
$result)
357 if($ilAccess->checkAccess(
'read',
'',$result[
'id']))
364 return $checked_result ? $checked_result : array();
372 $new_result = array();
377 $this->result[
'lm'][
'meta'] = $this->
__checkAccess($this->result[
'lm'][
'meta'],
'lm');
378 if(is_array($this->result[
'lm'][
'meta']))
380 foreach($this->result[
'lm'][
'meta'] as
$data)
382 if($tree->isInTree($data[
'id']))
384 $new_result[
'lm'][
'meta'][] =
$data;
388 $this->result[
'lm'][
'content'] = $this->
__checkAccess($this->result[
'lm'][
'content'],
'lm');
389 if(is_array($this->result[
'lm'][
'content']))
391 foreach($this->result[
'lm'][
'content'] as
$data)
393 if($tree->isInTree($data[
'id']))
395 $new_result[
'lm'][
'content'][] =
$data;
399 $this->result[
'dbk'][
'meta'] = $this->
__checkAccess($this->result[
'dbk'][
'meta'],
'dbk');
400 if(is_array($this->result[
'dbk'][
'meta']))
402 foreach($this->result[
'dbk'][
'meta'] as
$data)
404 if($tree->isInTree($data[
'id']))
406 $new_result[
'dbk'][
'meta'][] =
$data;
410 $this->result[
'dbk'][
'content'] = $this->
__checkAccess($this->result[
'dbk'][
'content'],
'dbk');
411 if(is_array($this->result[
'dbk'][
'content']))
413 foreach($this->result[
'dbk'][
'content'] as
$data)
415 if($tree->isInTree($data[
'id']))
417 $new_result[
'dbk'][
'content'][] =
$data;
421 $this->result[
'grp'] = $this->
__checkAccess($this->result[
'grp'],
'grp');
422 if(is_array($this->result[
'grp']))
424 foreach($this->result[
'grp'] as
$data)
426 if($tree->isInTree($data[
'id']))
428 $new_result[
'grp'][] =
$data;
432 if(is_array($this->result[
'usr']))
434 foreach($this->result[
'usr'] as $user)
438 $new_result[
'usr'][] = $user;
442 if(is_array($this->result[
'role']))
444 foreach($this->result[
'role'] as $user)
448 $new_result[
'role'][] = $user;
459 $word = trim($a_word);
461 if(!preg_match(
'/\*/',$word))
463 return '%'.$word.
'%';
465 if(preg_match(
'/^\*/',$word))
467 return str_replace(
'*',
'%',$word);
471 return '% '.str_replace(
'*',
'%',$word);
481 include_once
'Services/Search/classes/class.ilObjectSearchFactory.php';
486 foreach(array(
"login",
"firstname",
"lastname",
"title",
487 "email",
"institution",
"street",
"city",
"zipcode",
"country",
"phone_home",
"fax") as $field)
489 $user_search->setFields(array($field));
490 $tmp_res = $user_search->performSearch();
492 $res->mergeEntries($tmp_res);
495 foreach(
$res->getEntries() as $id =>
$data)
500 return $users ? $users : array();
509 include_once
'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
511 $object_search->setFilter(array($a_type));
512 $res = $object_search->performSearch();
516 foreach(
$res->getResultIds() as $id)
518 $objs[$counter++][
'id'] = $id;
520 return $objs ? $objs : array();
531 include_once
'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
533 $object_search->setFilter(array(
'role'));
535 $res = $object_search->performSearch();
536 foreach(
$res->getEntries() as $id =>
$data)
541 return $roles ? $roles : array();