ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $db = null;
22  /*
23  * instance of query parser
24  */
25  var $query_parser = null;
26 
27  /*
28  * instance of result obj
29  */
30  var $search_result = null;
31 
32  /*
33  * List of all searchable objects
34  */
35  var $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
36  'chat','icrs','icla','webr','mcst','sess','pg','st','wiki');
37 
38  private $id_filter = array();
39 
40 
45  function ilAbstractSearch(&$qp_obj)
46  {
47  global $ilDB;
48 
49  $this->query_parser =& $qp_obj;
50  $this->db =& $ilDB;
51 
52  include_once 'Services/Search/classes/class.ilSearchResult.php';
53 
54  $this->search_result = new ilSearchResult();
55  }
56 
62  function setFields($a_fields)
63  {
64  $this->fields = $a_fields;
65  }
66 
72  function getFields()
73  {
74  return $this->fields ? $this->fields : array();
75  }
76 
82  function setFilter($a_filter)
83  {
84  if(is_array($a_filter))
85  {
86  $this->object_types = $a_filter;
87  }
88  }
89 
95  public function setIdFilter($a_id_filter)
96  {
97  $this->id_filter = $a_id_filter;
98  }
99 
104  public function getIdFilter()
105  {
106  return (array) $this->id_filter;
107  }
108 
114  function appendToFilter($a_type)
115  {
116  if(is_array($this->object_types))
117  {
118  if(in_array($a_type,$this->object_types))
119  {
120  return false;
121  }
122  }
123  $this->object_types[] = $a_type;
124 
125  return true;
126  }
127 
128 
134  function getFilter()
135  {
136  return $this->object_types ? $this->object_types : array();
137  }
138 
145  {
146  global $ilDB;
147 
148  if($this->query_parser->getCombination() == 'or')
149  {
150  return '';
151  }
152  if(count($this->fields) > 1)
153  {
154  foreach($this->fields as $field)
155  {
156  $tmp_fields[] = array($field,'text');
157  }
158  $complete_str = $ilDB->concat($tmp_fields);
159 
160  /*
161  $complete_str = 'CONCAT(';
162  $complete_str .= implode(',',$this->fields);
163  $complete_str .= ')';
164  */
165  }
166  else
167  {
168  $complete_str = $this->fields[0];
169  }
170 
171  $counter = 0;
172  foreach($this->query_parser->getQuotedWords() as $word)
173  {
174  $locate .= ',';
175  $locate .= $ilDB->locate($ilDB->quote($word,'text'),$complete_str);
176  $locate .= (' found'.$counter++);
177  $locate .= ' ';
178  #$locate .= (", LOCATE('".$word."',".$complete_str.") ");
179  #$locate .= ("as found".$counter++." ");
180  }
181 
182  return $locate;
183  }
184 
185  function __prepareFound(&$row)
186  {
187  if($this->query_parser->getCombination() == 'or')
188  {
189  return array();
190  }
191  $counter = 0;
192  foreach($this->query_parser->getQuotedWords() as $word)
193  {
194  $res_found = "found".$counter++;
195  $found[] = $row->$res_found;
196  }
197  return $found ? $found : array();
198  }
199 
200  function &performSearch()
201  {
202  echo "Should be overwritten.";
203  }
204 
205 
206 }
207 ?>