ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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');
37 
38  private $id_filter = array();
39 
40 
45  public function __construct($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  public function setFields($a_fields)
63  {
64  $this->fields = $a_fields;
65  }
66 
72  public function getFields()
73  {
74  return $this->fields ? $this->fields : array();
75  }
76 
82  public function setFilter($a_filter)
83  {
84  if (is_array($a_filter)) {
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  public function appendToFilter($a_type)
114  {
115  if (is_array($this->object_types)) {
116  if (in_array($a_type, $this->object_types)) {
117  return false;
118  }
119  }
120  $this->object_types[] = $a_type;
121 
122  return true;
123  }
124 
125 
131  public function getFilter()
132  {
133  return $this->object_types ? $this->object_types : array();
134  }
135 
141  public function __createLocateString()
142  {
143  global $ilDB;
144 
145  if ($this->query_parser->getCombination() == 'or') {
146  return '';
147  }
148  if (count($this->fields) > 1) {
149  foreach ($this->fields as $field) {
150  $tmp_fields[] = array($field,'text');
151  }
152  $complete_str = $ilDB->concat($tmp_fields);
153 
154  /*
155  $complete_str = 'CONCAT(';
156  $complete_str .= implode(',',$this->fields);
157  $complete_str .= ')';
158  */
159  } else {
160  $complete_str = $this->fields[0];
161  }
162 
163  $counter = 0;
164  foreach ($this->query_parser->getQuotedWords() as $word) {
165  $locate .= ',';
166  $locate .= $ilDB->locate($ilDB->quote($word, 'text'), $complete_str);
167  $locate .= (' found' . $counter++);
168  $locate .= ' ';
169  #$locate .= (", LOCATE('".$word."',".$complete_str.") ");
170  #$locate .= ("as found".$counter++." ");
171  }
172 
173  return $locate;
174  }
175 
176  public function __prepareFound(&$row)
177  {
178  if ($this->query_parser->getCombination() == 'or') {
179  return array();
180  }
181  $counter = 0;
182  foreach ($this->query_parser->getQuotedWords() as $word) {
183  $res_found = "found" . $counter++;
184  $found[] = $row->$res_found;
185  }
186  return $found ? $found : array();
187  }
188 
189  public function performSearch()
190  {
191  echo "Should be overwritten.";
192  }
193 }
getFields()
Get fields to search.
__construct($qp_obj)
Constructor public.
__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
$counter
$a_type
Definition: workflow.php:92
getIdFilter()
Get Id filter.
Create styles array
The data for the language used.
appendToFilter($a_type)
Append object type to filter.
global $ilDB