ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchAutoComplete.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Search/classes/class.ilSearchSettings.php';
5 
11 {
12 
16  public static function getLuceneList($a_str)
17  {
18  include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
19  $qp = new ilLuceneQueryParser('title:'.$a_str.'*');
20  $qp->parse();
21 
22  include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
23  $searcher = ilLuceneSearcher::getInstance($qp);
24  $searcher->setType(ilLuceneSearcher::TYPE_STANDARD);
25  $searcher->search();
26 
27  $res = $searcher->getResult()->getCandidates();
28 
29  $max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength() ?
30  ilSearchSettings::getInstance()->getAutoCompleteLength() :
31  10;
32 
33 
34  $list = array();
35  $num_entries = 0;
36  foreach($res as $res_obj_id)
37  {
38  if(self::checkObjectPermission($res_obj_id))
39  {
40  $list[] = ilObject::_lookupTitle($res_obj_id,true);
41  $num_entries++;
42  }
43  if($num_entries >= $max_entries)
44  {
45  break;
46  }
47  }
48 
49  $i = 0;
50  $result = array();
51  foreach($list as $entry)
52  {
53  $result[$i] = new stdClass();
54  $result[$i]->value = $entry;
55  $i++;
56  }
57  include_once './Services/JSON/classes/class.ilJsonUtil.php';
59  }
60 
61 
62 
66  static function getList($a_str)
67  {
68  global $ilDB;
69 
70  include_once './Services/Search/classes/class.ilSearchSettings.php';
71  if(ilSearchSettings::getInstance()->isLuceneUserSearchEnabled())
72  {
73  return self::getLuceneList($a_str);
74  }
75 
76 
77  $a_str = str_replace('"', "", $a_str);
78 
79  $settings = new ilSearchSettings();
80 
81  $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
82  'chat','icrs','icla','webr','mcst','sess','pg','st','gdf','wiki');
83 
84  $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
85  .$ilDB->like('title', 'text', $a_str."%")." AND "
86  .$ilDB->in('type', $object_types, false, 'text')." ORDER BY title");
87  $max = ($settings->getAutoCompleteLength() > 0)
88  ? $settings->getAutoCompleteLength()
89  : 10;
90 
91  $cnt = 0;
92  $list = array();
93  $checked = array();
94  $lim = "";
95  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
96  {
97  if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0)
98  {
99  $rec["title"] = '"'.$rec["title"].'"';
100  }
101  if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked))
102  {
104  {
105  $list[] = $lim.$rec["title"];
106  $cnt++;
107  }
108  $checked[] = $rec["obj_id"];
109  }
110  }
111 
112  $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
113  .$ilDB->like('keyword', 'text', $a_str."%")." AND "
114  .$ilDB->in('obj_type', $object_types, false, 'text')." ORDER BY keyword");
115  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
116  {
117  if (strpos($rec["keyword"], " ") > 0)
118  {
119  $rec["keyword"] = '"'.$rec["keyword"].'"';
120  }
121  if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked))
122  {
123  if (ilSearchAutoComplete::checkObjectPermission($rec["rbac_id"]))
124  {
125  $list[] = $lim.$rec["keyword"];
126  $cnt++;
127  }
128  }
129  $checked[] = $rec["rbac_id"];
130  }
131 
132  $i = 0;
133  $result = array();
134  foreach ($list as $l)
135  {
136  $result[$i] = new stdClass();
137  $result[$i]->value = $l;
138  $i++;
139  }
140 
141  include_once './Services/JSON/classes/class.ilJsonUtil.php';
142  return ilJsonUtil::encode($result);
143  }
144 
148  static function checkObjectPermission($a_obj_id)
149  {
150  global $ilAccess;
151 
152  $refs = ilObject::_getAllReferences($a_obj_id);
153  foreach ($refs as $ref)
154  {
155  if ($ilAccess->checkAccess("read", "", $ref))
156  {
157  return true;
158  }
159  }
160  return false;
161  }
162 }
163 ?>