ILIAS  eassessment Revision 61809
 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','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl', 'icrs','icla','webr','mcst','sess','pg','st','book');
36 
37  private $id_filter = array();
38 
39 
44  function ilAbstractSearch(&$qp_obj)
45  {
46  global $ilDB;
47 
48  $this->query_parser =& $qp_obj;
49  $this->db =& $ilDB;
50 
51  include_once 'Services/Search/classes/class.ilSearchResult.php';
52 
53  $this->search_result = new ilSearchResult();
54  }
55 
61  function setFields($a_fields)
62  {
63  $this->fields = $a_fields;
64  }
65 
71  function getFields()
72  {
73  return $this->fields ? $this->fields : array();
74  }
75 
81  function setFilter($a_filter)
82  {
83  if(is_array($a_filter))
84  {
85  $this->object_types = $a_filter;
86  }
87  }
88 
94  public function setIdFilter($a_id_filter)
95  {
96  $this->id_filter = $a_id_filter;
97  }
98 
103  public function getIdFilter()
104  {
105  return (array) $this->id_filter;
106  }
107 
113  function appendToFilter($a_type)
114  {
115  if(is_array($this->object_types))
116  {
117  if(in_array($a_type,$this->object_types))
118  {
119  return false;
120  }
121  }
122  $this->object_types[] = $a_type;
123 
124  return true;
125  }
126 
127 
133  function getFilter()
134  {
135  return $this->object_types ? $this->object_types : array();
136  }
137 
144  {
145  global $ilDB;
146 
147  if($this->query_parser->getCombination() == 'or')
148  {
149  return '';
150  }
151  if(count($this->fields) > 1)
152  {
153  foreach($this->fields as $field)
154  {
155  $tmp_fields[] = array($field,'text');
156  }
157  $complete_str = $ilDB->concat($tmp_fields);
158 
159  /*
160  $complete_str = 'CONCAT(';
161  $complete_str .= implode(',',$this->fields);
162  $complete_str .= ')';
163  */
164  }
165  else
166  {
167  $complete_str = $this->fields[0];
168  }
169 
170  $counter = 0;
171  foreach($this->query_parser->getQuotedWords() as $word)
172  {
173  $locate .= ',';
174  $locate .= $ilDB->locate($ilDB->quote($word,'text'),$complete_str);
175  $locate .= (' found'.$counter++);
176  $locate .= ' ';
177  #$locate .= (", LOCATE('".$word."',".$complete_str.") ");
178  #$locate .= ("as found".$counter++." ");
179  }
180 
181  return $locate;
182  }
183 
184  function __prepareFound(&$row)
185  {
186  if($this->query_parser->getCombination() == 'or')
187  {
188  return array();
189  }
190  $counter = 0;
191  foreach($this->query_parser->getQuotedWords() as $word)
192  {
193  $res_found = "found".$counter++;
194  $found[] = $row->$res_found;
195  }
196  return $found ? $found : array();
197  }
198 
199  function &performSearch()
200  {
201  echo "Should be overwritten.";
202  }
203 
204 
205 }
206 ?>