ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  if (self::checkObjectPermission($res_obj_id)) {
38  $list[] = ilObject::_lookupTitle($res_obj_id, true);
39  $num_entries++;
40  }
41  if ($num_entries >= $max_entries) {
42  break;
43  }
44  }
45 
46  $i = 0;
47  $result = array();
48  foreach ($list as $entry) {
49  $result[$i] = new stdClass();
50  $result[$i]->value = '"' . $entry . '"';
51  $i++;
52  }
53  include_once './Services/JSON/classes/class.ilJsonUtil.php';
55  }
56 
57 
58 
62  public static function getList($a_str)
63  {
64  global $ilDB;
65 
66  include_once './Services/Search/classes/class.ilSearchSettings.php';
67  if (ilSearchSettings::getInstance()->enabledLucene()) {
68  return self::getLuceneList($a_str);
69  }
70 
71 
72  $a_str = str_replace('"', "", $a_str);
73 
74  $settings = new ilSearchSettings();
75 
76  $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
77  'chat', 'webr','mcst','sess','pg','st','gdf','wiki');
78 
79  $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
80  . $ilDB->like('title', 'text', $a_str . "%") . " AND "
81  . $ilDB->in('type', $object_types, false, 'text') . " ORDER BY title");
82  $max = ($settings->getAutoCompleteLength() > 0)
83  ? $settings->getAutoCompleteLength()
84  : 10;
85 
86  $cnt = 0;
87  $list = array();
88  $checked = array();
89  $lim = "";
90  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
91  if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0) {
92  $rec["title"] = '"' . $rec["title"] . '"';
93  }
94  if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked)) {
95  if (ilSearchAutoComplete::checkObjectPermission($rec["obj_id"])) {
96  $list[] = $lim . $rec["title"];
97  $cnt++;
98  }
99  $checked[] = $rec["obj_id"];
100  }
101  }
102 
103  $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
104  . $ilDB->like('keyword', 'text', $a_str . "%") . " AND "
105  . $ilDB->in('obj_type', $object_types, false, 'text') . " ORDER BY keyword");
106  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
107  if (strpos($rec["keyword"], " ") > 0) {
108  $rec["keyword"] = '"' . $rec["keyword"] . '"';
109  }
110  if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked)) {
111  if (ilSearchAutoComplete::checkObjectPermission($rec["rbac_id"])) {
112  $list[] = $lim . $rec["keyword"];
113  $cnt++;
114  }
115  }
116  $checked[] = $rec["rbac_id"];
117  }
118 
119  $i = 0;
120  $result = array();
121  foreach ($list as $l) {
122  $result[$i] = new stdClass();
123  $result[$i]->value = $l;
124  $i++;
125  }
126 
127  include_once './Services/JSON/classes/class.ilJsonUtil.php';
128  return ilJsonUtil::encode($result);
129  }
130 
134  public static function checkObjectPermission($a_obj_id)
135  {
136  global $ilAccess;
137 
138  $refs = ilObject::_getAllReferences($a_obj_id);
139  foreach ($refs as $ref) {
140  if ($ilAccess->checkAccess("read", "", $ref)) {
141  return true;
142  }
143  }
144  return false;
145  }
146 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$result
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static getList($a_str)
Get completion list.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static getLuceneList($a_str)
Performs better than standard like search on huge installations.
static encode($mixed, $suppress_native=false)
foreach($_POST as $key=> $value) $res
Search Auto Completion Application Class.
Create styles array
The data for the language used.
static checkObjectPermission($a_obj_id)
Checks read permission on obj id.
global $l
Definition: afr.php:30
global $ilDB
$i
Definition: disco.tpl.php:19