59 function ilSearch($a_user_id = 0,$a_read =
false)
66 $this->lng->loadLanguageModule(
"search");
68 $this->user_id = $a_user_id;
72 $this->read_db_result = $a_read;
75 #$this->__readDBResult();
81 $this->search_string = trim($a_search_str);
86 $this->combination = $a_combination;
90 $this->search_for = $a_search_for;
94 $this->search_in = $a_search_in;
98 $this->result = $a_result;
102 $this->search_type = $a_type;
106 $this->perform_update = $a_value;
110 $this->allow_empty_search = $a_value;
115 $this->min_word_length = $a_min_word_length;
133 return $this->combination ? $this->combination :
"or";
137 return $this->search_for ? $this->search_for : array();
141 return $this->search_in ? $this->search_in : array();
145 if($a_type ==
'lm' or $a_type ==
'dbk')
147 return $this->search_in[$a_type];
156 return $this->result ? $this->result : array();
160 return $this->result[$a_type] ? $this->result[$a_type] : array();
182 $number += count($tmp_res[
"meta"]) + count($tmp_res[
"content"]);
185 $number += count($tmp_res[
"meta"]) + count($tmp_res[
"content"]);
198 $message .= $this->lng->txt(
"search_no_search_term").
"<br/>";
209 $message .= $this->lng->txt(
"search_no_category").
"<br/>";
220 $ilBench->start(
"Search",
"performSearch");
222 $result = array(
"usr" => array(),
235 $this->act_type =
'usr';
240 include_once
"./Modules/Group/classes/class.ilObjGroup.php";
242 $this->act_type =
'grp';
248 include_once
"./Modules/LearningModule/classes/class.ilObjContentObject.php";
249 $this->act_type =
'lm';
256 include_once
"./Modules/LearningModule/classes/class.ilObjDlBook.php";
257 $this->act_type =
'dbk';
264 include_once
"./Services/AccessControl/classes/class.ilObjRole.php";
266 $this->act_type =
'role';
269 #$result["role"] = $this->__checkAccess($result["role"],'role');
282 $ilBench->stop(
"Search",
"performSearch");
314 # if(count($this->__getResultIdsByActualType()))
329 $concat =
"CONCAT(\" \",";
330 $concat .= implode(
",\" \",",$a_fields);
336 foreach ($this->parsed_str[
"and"] as $and)
340 $where .=
"LIKE(\"".$and.
"\") ";
344 foreach ($this->parsed_str[
"not"] as $not)
348 $where .=
"NOT LIKE(\"".$not.
"\") ";
351 if (count($this->parsed_str[
"or"]) and
352 !count($this->parsed_str[
"and"]) and
353 !count($this->parsed_str[
"not"]))
357 foreach ($this->parsed_str[
"all"] as $or)
360 $where .=
"LIKE(\"".$or.
"\") ";
374 $match =
" MATCH(".implode(
",",$a_fields).
") ";
378 if (count($this->parsed_str[
"or"]))
382 $where .=
" AGAINST('".implode(
" ",$this->parsed_str[
"all"]).
"') ";
385 foreach ($this->parsed_str[
"and"] as $and)
389 $where .=
"AGAINST('".$and.
"') ";
408 $this->parsed_str[
"and"] = $this->parsed_str[
"or"] = $this->parsed_str[
"not"] = array();
410 foreach ($tmp_arr as $word)
412 #$word = trim($word);
416 if (substr($word,0,1) ==
'+')
418 $this->parsed_str[
"all"][] = substr($word,1);
419 $this->parsed_str[
"and"][] = substr($word,1);
423 if (substr($word,0,1) ==
'-')
426 #$this->parsed_str["all"][] = substr($word,1);
427 $this->parsed_str[
"not"][] = substr($word,1);
433 $this->parsed_str[
"all"][] = $word;
434 $this->parsed_str[
"and"][] = $word;
440 $this->parsed_str[
"all"][] = $word;
441 $this->parsed_str[
"or"][] = $word;
450 foreach ($this->parsed_str as $type)
452 foreach ($type as $word)
463 $message .= ($this->lng->txt(
'search_to_short').
'<br />');
464 $message .= ($this->lng->txt(
'search_minimum_characters').
' '.$this->
getMinWordLength().
'<br />');
476 $query =
"REPLACE INTO usr_search ".
477 "VALUES(".$this->ilias->db->quote($this->
getUserId()).
",'".addslashes(serialize($this->
getResults())).
"','0')";
479 $res = $this->ilias->db->query($query);
489 if ($this->
getUserId() != 0 and $this->
getUserId() != ANONYMOUS_USER_ID and $this->read_db_result)
491 $query =
"SELECT search_result FROM usr_search ".
492 "WHERE usr_id = ".$this->ilias->db->quote($this->
getUserId()).
" ";
494 $res = $this->ilias->db->query($query);
499 $this->
setResult(unserialize(stripslashes($row->search_result)));
527 switch ($this->act_type)
540 $ids[] = $result[
"id"];
543 return $ids ? $ids : array();
550 if (is_array($a_results))
552 foreach ($a_results as
$result)
554 if($ilAccess->checkAccess(
'read',
'',$result[
'id']))
560 return $checked_result ? $checked_result : array();
566 include_once
'./payment/classes/class.ilPaymentObject.php';
567 include_once
'./Modules/Course/classes/class.ilObjCourse.php';
571 if(!$tree->isInTree($a_ref_id))
575 foreach($tree->getPathFull($a_ref_id) as $node_data)
601 $new_result = array();
606 $this->result[
'lm'][
'meta'] = $this->
__checkAccess($this->result[
'lm'][
'meta'],
'lm');
607 if(is_array($this->result[
'lm'][
'meta']))
609 foreach($this->result[
'lm'][
'meta'] as
$data)
611 if($tree->isInTree($data[
'id']))
613 $new_result[
'lm'][
'meta'][] =
$data;
617 $this->result[
'lm'][
'content'] = $this->
__checkAccess($this->result[
'lm'][
'content'],
'lm');
618 if(is_array($this->result[
'lm'][
'content']))
620 foreach($this->result[
'lm'][
'content'] as
$data)
622 if($tree->isInTree($data[
'id']))
624 $new_result[
'lm'][
'content'][] =
$data;
628 $this->result[
'dbk'][
'meta'] = $this->
__checkAccess($this->result[
'dbk'][
'meta'],
'dbk');
629 if(is_array($this->result[
'dbk'][
'meta']))
631 foreach($this->result[
'dbk'][
'meta'] as
$data)
633 if($tree->isInTree($data[
'id']))
635 $new_result[
'dbk'][
'meta'][] =
$data;
639 $this->result[
'dbk'][
'content'] = $this->
__checkAccess($this->result[
'dbk'][
'content'],
'dbk');
640 if(is_array($this->result[
'dbk'][
'content']))
642 foreach($this->result[
'dbk'][
'content'] as
$data)
644 if($tree->isInTree($data[
'id']))
646 $new_result[
'dbk'][
'content'][] =
$data;
650 $this->result[
'grp'] = $this->
__checkAccess($this->result[
'grp'],
'grp');
651 if(is_array($this->result[
'grp']))
653 foreach($this->result[
'grp'] as
$data)
655 if($tree->isInTree($data[
'id']))
657 $new_result[
'grp'][] =
$data;
661 if(is_array($this->result[
'usr']))
663 foreach($this->result[
'usr'] as
$user)
667 $new_result[
'usr'][] =
$user;
671 if(is_array($this->result[
'role']))
673 foreach($this->result[
'role'] as
$user)
677 $new_result[
'role'][] =
$user;
688 $word = trim($a_word);
690 if(!preg_match(
'/\*/',$word))
692 return '%'.$word.
'%';
694 if(preg_match(
'/^\*/',$word))
696 return str_replace(
'*',
'%',$word);
700 return '% '.str_replace(
'*',
'%',$word);