ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAbstractSearch.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
17 {
18  /*
19  * instance of db object
20  */
21  public $db = null;
22  /*
23  * instance of query parser
24  */
25  public $query_parser = null;
26 
27  /*
28  * instance of result obj
29  */
30  public $search_result = null;
31 
32  /*
33  * List of all searchable objects
34  */
35  public $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
36  'chat','webr','mcst','sess','pg','st','wiki','book', 'copa');
37 
38  private $id_filter = array();
39 
40 
45  public function __construct($qp_obj)
46  {
47  global $DIC;
48 
49  $ilDB = $DIC['ilDB'];
50 
51  $this->query_parser = $qp_obj;
52  $this->db = $ilDB;
53 
54  include_once 'Services/Search/classes/class.ilSearchResult.php';
55 
56  $this->search_result = new ilSearchResult();
57  }
58 
64  public function setFields($a_fields)
65  {
66  $this->fields = $a_fields;
67  }
68 
74  public function getFields()
75  {
76  return $this->fields ? $this->fields : array();
77  }
78 
84  public function setFilter($a_filter)
85  {
86  if (is_array($a_filter)) {
87  $this->object_types = $a_filter;
88  }
89  }
90 
96  public function setIdFilter($a_id_filter)
97  {
98  $this->id_filter = $a_id_filter;
99  }
100 
105  public function getIdFilter()
106  {
107  return (array) $this->id_filter;
108  }
109 
115  public function appendToFilter($a_type)
116  {
117  if (is_array($this->object_types)) {
118  if (in_array($a_type, $this->object_types)) {
119  return false;
120  }
121  }
122  $this->object_types[] = $a_type;
123 
124  return true;
125  }
126 
127 
133  public function getFilter()
134  {
135  return $this->object_types ? $this->object_types : array();
136  }
137 
143  public function __createLocateString()
144  {
145  global $DIC;
146 
147  $ilDB = $DIC['ilDB'];
148 
149  if ($this->query_parser->getCombination() == 'or') {
150  return '';
151  }
152  if (count($this->fields) > 1) {
153  foreach ($this->fields as $field) {
154  $tmp_fields[] = array($field,'text');
155  }
156  $complete_str = $ilDB->concat($tmp_fields);
157 
158  /*
159  $complete_str = 'CONCAT(';
160  $complete_str .= implode(',',$this->fields);
161  $complete_str .= ')';
162  */
163  } else {
164  $complete_str = $this->fields[0];
165  }
166 
167  $counter = 0;
168  foreach ($this->query_parser->getQuotedWords() as $word) {
169  $locate .= ',';
170  $locate .= $ilDB->locate($ilDB->quote($word, 'text'), $complete_str);
171  $locate .= (' found' . $counter++);
172  $locate .= ' ';
173  #$locate .= (", LOCATE('".$word."',".$complete_str.") ");
174  #$locate .= ("as found".$counter++." ");
175  }
176 
177  return $locate;
178  }
179 
180  public function __prepareFound(&$row)
181  {
182  if ($this->query_parser->getCombination() == 'or') {
183  return array();
184  }
185  $counter = 0;
186  foreach ($this->query_parser->getQuotedWords() as $word) {
187  $res_found = "found" . $counter++;
188  $found[] = $row->$res_found;
189  }
190  return $found ? $found : array();
191  }
192 
193  public function performSearch()
194  {
195  echo "Should be overwritten.";
196  }
197 }
getFields()
Get fields to search.
__construct($qp_obj)
Constructor public.
global $DIC
Definition: saml.php:7
__createLocateString()
build locate string in case of AND search
setIdFilter($a_id_filter)
Set id filter Filters search by given object id.
setFilter($a_filter)
set object type to search in
setFields($a_fields)
Set fields to search.
getFilter()
get object type to search in
$errors fields
Definition: imgupload.php:51
$a_type
Definition: workflow.php:92
getIdFilter()
Get Id filter.
$row
appendToFilter($a_type)
Append object type to filter.
global $ilDB