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