ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAbstractSearch.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
37 {
38  /*
39  * instance of db object
40  */
41  var $db = null;
42  /*
43  * instance of query parser
44  */
45  var $query_parser = null;
46 
47  /*
48  * instance of result obj
49  */
50  var $search_result = null;
51 
52  /*
53  * List of all searchable objects
54  */
55  var $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
56  'chat','icrs','icla','webr','mcst','sess','pg','st','wiki');
57 
58 
63  function ilAbstractSearch(&$qp_obj)
64  {
65  global $ilDB;
66 
67  $this->query_parser =& $qp_obj;
68  $this->db =& $ilDB;
69 
70  include_once 'Services/Search/classes/class.ilSearchResult.php';
71 
72  $this->search_result = new ilSearchResult();
73  }
74 
80  function setFields($a_fields)
81  {
82  $this->fields = $a_fields;
83  }
84 
90  function getFields()
91  {
92  return $this->fields ? $this->fields : array();
93  }
94 
100  function setFilter($a_filter)
101  {
102  if(is_array($a_filter))
103  {
104  $this->object_types = $a_filter;
105  }
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  if($this->query_parser->getCombination() == 'or')
146  {
147  return '';
148  }
149  if(count($this->fields) > 1)
150  {
151  $complete_str = 'CONCAT(';
152  $complete_str .= implode(',',$this->fields);
153  $complete_str .= ')';
154  }
155  else
156  {
157  $complete_str = $this->fields[0];
158  }
159 
160  $counter = 0;
161  foreach($this->query_parser->getQuotedWords() as $word)
162  {
163  $locate .= (", LOCATE('".$word."',".$complete_str.") ");
164  $locate .= ("as found".$counter++." ");
165  }
166 
167  return $locate;
168  }
169 
170  function __prepareFound(&$row)
171  {
172  if($this->query_parser->getCombination() == 'or')
173  {
174  return array();
175  }
176  $counter = 0;
177  foreach($this->query_parser->getQuotedWords() as $word)
178  {
179  $res_found = "found".$counter++;
180  $found[] = $row->$res_found;
181  }
182  return $found ? $found : array();
183  }
184 
185  function &performSearch()
186  {
187  echo "Should be overwritten.";
188  }
189 
190 
191 }
192 ?>