ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  const LIKE_SEARCH = 0;
17  const INDEX_SEARCH = 1;
18  const LUCENE_SEARCH = 2;
19 
20  const OPERATOR_AND = 1;
21  const OPERATOR_OR = 2;
22 
23  protected static $instance = null;
24 
26  protected $fragmentSize = 30;
27  protected $fragmentCount = 3;
28  protected $numSubitems = 5;
29  protected $showRelevance = true;
30  protected $last_index_date = null;
31  protected $lucene_item_filter_enabled = false;
32  protected $lucene_item_filter = array();
33 
34 
35 
36  var $ilias = null;
37  var $max_hits = null;
38  var $index = null;
39 
40  function ilSearchSettings()
41  {
42  global $ilias;
43 
44  $this->ilias =& $ilias;
45  $this->__read();
46  }
47 
54  public static function getInstance()
55  {
56  if(self::$instance == null)
57  {
58  return self::$instance = new ilSearchSettings();
59  }
60  return self::$instance;
61  }
62 
68  public static function getLuceneItemFilterDefinitions()
69  {
70  return array(
71  'crs' => array('filter' => 'type:crs','trans' => 'objs_crs'),
72  'grp' => array('filter' => 'type:grp', 'trans' => 'objs_grp'),
73  'lms' => array('filter' => 'type:lm OR type:htlm OR type:sahs OR type:dbk','trans' => 'learning_resource'),
74  'glo' => array('filter' => 'type:glo','trans' => 'objs_glo'),
75  'mep' => array('filter' => 'type:mep', 'trans' => 'objs_mep'),
76  'tst' => array('filter' => 'type:tst OR type:svy OR type:qpl OR type:spl','trans' => 'search_tst_svy'),
77  'frm' => array('filter' => 'type:frm','trans' => 'objs_frm'),
78  'exc' => array('filter' => 'type:exc','trans' => 'objs_exc'),
79  'file' => array('filter' => 'type:file','trans' => 'objs_file'),
80  'mcst' => array('filter' => 'type:mcst','trans' => 'objs_mcst'),
81  'wiki' => array('filter' => 'type:wiki','trans' => 'objs_wiki')
82  );
83  }
84 
91  {
92  if(!$this->isLuceneItemFilterEnabled())
93  {
94  return array();
95  }
96 
97  $filter = $this->getLuceneItemFilter();
98  $enabled = array();
99  foreach(self::getLuceneItemFilterDefinitions() as $obj => $def)
100  {
101  if(isset($filter[$obj]) and $filter[$obj])
102  {
103  $enabled[$obj] = $def;
104  }
105  }
106  return $enabled;
107  }
108 
115  {
116  global $ilDB;
117 
118  static $seas_ref_id = 0;
119 
120  if($seas_ref_id)
121  {
122  return $seas_ref_id;
123  }
124  $query = "SELECT object_reference.ref_id as ref_id FROM object_reference,tree,object_data ".
125  "WHERE tree.parent = ".$ilDB->quote(SYSTEM_FOLDER_ID,'integer')." ".
126  "AND object_data.type = 'seas' ".
127  "AND object_reference.ref_id = tree.child ".
128  "AND object_reference.obj_id = object_data.obj_id";
129 
130  $res = $ilDB->query($query);
131  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
132 
133  return $seas_ref_id = $row->ref_id;
134  }
135 
136  function enabledIndex()
137  {
138  global $ilDB;
139 
140  if($ilDB->getDBType() == 'oracle')
141  {
142  return false;
143  }
144  return $this->index ? true : false;
145  }
146  function enableIndex($a_status)
147  {
148  $this->index = $a_status;
149  }
150  function enabledLucene()
151  {
152  return $this->lucene ? true : false;
153  }
154  function enableLucene($a_status)
155  {
156  $this->lucene = $a_status ? true : false;
157  }
158 
159  function getMaxHits()
160  {
161  return $this->max_hits;
162  }
163  function setMaxHits($a_max_hits)
164  {
165  $this->max_hits = $a_max_hits;
166  }
167 
168  // BEGIN PATCH Lucene search
169  public function getDefaultOperator()
170  {
172  }
173 
174  public function setDefaultOperator($a_op)
175  {
176  $this->default_operator = $a_op;
177  }
178 
179  public function setFragmentSize($a_size)
180  {
181  $this->fragmentSize = $a_size;
182  }
183 
184  public function getFragmentSize()
185  {
186  return $this->fragmentSize;
187  }
188 
189  public function setFragmentCount($a_count)
190  {
191  $this->fragmentCount = $a_count;
192  }
193 
194  public function getHideAdvancedSearch()
195  {
196  return $this->hide_adv_search ? true : false;
197  }
198  public function setHideAdvancedSearch($a_status)
199  {
200  $this->hide_adv_search = $a_status;
201  }
202  public function getAutoCompleteLength()
203  {
204  return $this->auto_complete_length;
205  }
206  public function setAutoCompleteLength($auto_complete_length)
207  {
208  $this->auto_complete_length = $auto_complete_length;
209  }
210 
211  public function getFragmentCount()
212  {
213  return $this->fragmentCount;
214  }
215 
216  public function setMaxSubitems($a_max)
217  {
218  $this->numSubitems = $a_max;
219  }
220 
221  public function getMaxSubitems()
222  {
223  return $this->numSubitems;
224  }
225 
226  public function isRelevanceVisible()
227  {
228  return $this->showRelevance;
229  }
230 
231  public function showRelevance($a_status)
232  {
233  $this->showRelevance = (bool) $a_status;
234  }
235 
236  public function getLastIndexTime()
237  {
238  return $this->last_index_date instanceof ilDateTime ?
239  $this->last_index_date :
240  new ilDateTime('2009-01-01 12:00:00',IL_CAL_DATETIME);
241  }
242 
243  public function enableLuceneItemFilter($a_status)
244  {
245  $this->lucene_item_filter_enabled = $a_status;
246  }
247 
248  public function isLuceneItemFilterEnabled()
249  {
251  }
252 
253  public function getLuceneItemFilter()
254  {
256  }
257 
258  public function setLuceneItemFilter($a_filter)
259  {
260  $this->lucene_item_filter = $a_filter;
261  }
262 
266  public function setLastIndexTime($time)
267  {
268  $this->last_index_date = $time;
269  }
270  // END PATCH Lucene Search
271 
272  function update()
273  {
274  // setSetting writes to db
275  $this->ilias->setSetting('search_max_hits',$this->getMaxHits());
276  $this->ilias->setSetting('search_index',(int) $this->enabledIndex());
277  $this->ilias->setSetting('search_lucene',(int) $this->enabledLucene());
278 
279  $this->ilias->setSetting('lucene_default_operator',$this->getDefaultOperator());
280  $this->ilias->setSetting('lucene_fragment_size',$this->getFragmentSize());
281  $this->ilias->setSetting('lucene_fragment_count',$this->getFragmentCount());
282  $this->ilias->setSetting('lucene_max_subitems',$this->getMaxSubitems());
283  $this->ilias->setSetting('lucene_show_relevance',$this->isRelevanceVisible());
284  $this->ilias->setSetting('lucene_last_index_time',$this->getLastIndexTime()->get(IL_CAL_UNIX));
285  $this->ilias->setSetting('hide_adv_search',(int) $this->getHideAdvancedSearch());
286  $this->ilias->setSetting('auto_complete_length',(int) $this->getAutoCompleteLength());
287  $this->ilias->setSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled());
288  $this->ilias->setSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
289 
290  return true;
291  }
292 
293  // PRIVATE
294  function __read()
295  {
296  $this->setMaxHits($this->ilias->getSetting('search_max_hits',10));
297  $this->enableIndex($this->ilias->getSetting('search_index',0));
298  $this->enableLucene($this->ilias->getSetting('search_lucene',0));
299 
300  $this->setDefaultOperator($this->ilias->getSetting('lucene_default_operator',self::OPERATOR_AND));
301  $this->setFragmentSize($this->ilias->getSetting('lucene_fragment_size',50));
302  $this->setFragmentCount($this->ilias->getSetting('lucene_fragment_count',3));
303  $this->setMaxSubitems($this->ilias->getSetting('lucene_max_subitems',5));
304  $this->showRelevance($this->ilias->getSetting('lucene_show_relevance',true));
305 
306  if($time = $this->ilias->getSetting('lucene_last_index_time',false))
307  {
308  $this->setLastIndexTime(new ilDateTime($time,IL_CAL_UNIX));
309  }
310  else
311  {
312  $this->setLastIndexTime(null);
313  }
314 
315  $this->setHideAdvancedSearch($this->ilias->getSetting('hide_adv_search',0));
316  $this->setAutoCompleteLength($this->ilias->getSetting('auto_complete_length',10));
317 
318  $this->enableLuceneItemFilter($this->ilias->getSetting('lucene_item_filter_enabled',(int) $this->isLuceneItemFilterEnabled()));
319 
320  $filter = $this->ilias->getSetting('lucene_item_filter',serialize($this->getLuceneItemFilter()));
321  $this->setLuceneItemFilter(unserialize($filter));
322  }
323 }
324 ?>