ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
65 
66  $ilDB = $DIC['ilDB'];
67 
68  include_once './Services/Search/classes/class.ilSearchSettings.php';
69  if (ilSearchSettings::getInstance()->enabledLucene()) {
70  return self::getLuceneList($a_str);
71  }
72 
73 
74  $a_str = str_replace('"', "", $a_str);
75 
76  $settings = new ilSearchSettings();
77 
78  $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
79  'chat', 'webr','mcst','sess','pg','st','gdf','wiki', 'copa');
80 
81  $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
82  . $ilDB->like('title', 'text', $a_str . "%") . " AND "
83  . $ilDB->in('type', $object_types, false, 'text') . " ORDER BY title");
84  $max = ($settings->getAutoCompleteLength() > 0)
85  ? $settings->getAutoCompleteLength()
86  : 10;
87 
88  $cnt = 0;
89  $list = array();
90  $checked = array();
91  $lim = "";
92  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
93  if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0) {
94  $rec["title"] = '"' . $rec["title"] . '"';
95  }
96  if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked)) {
97  if (ilSearchAutoComplete::checkObjectPermission($rec["obj_id"])) {
98  $list[] = $lim . $rec["title"];
99  $cnt++;
100  }
101  $checked[] = $rec["obj_id"];
102  }
103  }
104 
105  $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
106  . $ilDB->like('keyword', 'text', $a_str . "%") . " AND "
107  . $ilDB->in('obj_type', $object_types, false, 'text') . " ORDER BY keyword");
108  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
109  if (strpos($rec["keyword"], " ") > 0) {
110  $rec["keyword"] = '"' . $rec["keyword"] . '"';
111  }
112  if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked)) {
113  if (ilSearchAutoComplete::checkObjectPermission($rec["rbac_id"])) {
114  $list[] = $lim . $rec["keyword"];
115  $cnt++;
116  }
117  }
118  $checked[] = $rec["rbac_id"];
119  }
120 
121  $i = 0;
122  $result = array();
123  foreach ($list as $l) {
124  $result[$i] = new stdClass();
125  $result[$i]->value = $l;
126  $i++;
127  }
128 
129  include_once './Services/JSON/classes/class.ilJsonUtil.php';
130  return ilJsonUtil::encode($result);
131  }
132 
136  public static function checkObjectPermission($a_obj_id)
137  {
138  global $DIC;
139 
140  $ilAccess = $DIC['ilAccess'];
141 
142  $refs = ilObject::_getAllReferences($a_obj_id);
143  foreach ($refs as $ref) {
144  if ($ilAccess->checkAccess("read", "", $ref)) {
145  return true;
146  }
147  }
148  return false;
149  }
150 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$result
global $DIC
Definition: saml.php:7
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.
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