ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilSearchAutoComplete Class Reference

Search Auto Completion Application Class. More...

+ Collaboration diagram for ilSearchAutoComplete:

Static Public Member Functions

static getLuceneList ($a_str)
 Performs better than standard like search on huge installations. More...
 
static getList ($a_str)
 Get completion list. More...
 
static checkObjectPermission ($a_obj_id)
 Checks read permission on obj id. More...
 

Detailed Description

Search Auto Completion Application Class.

Definition at line 10 of file class.ilSearchAutoComplete.php.

Member Function Documentation

◆ checkObjectPermission()

static ilSearchAutoComplete::checkObjectPermission (   $a_obj_id)
static

Checks read permission on obj id.

Definition at line 136 of file class.ilSearchAutoComplete.php.

References $DIC, and ilObject\_getAllReferences().

Referenced by getList().

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  }
global $DIC
Definition: saml.php:7
static _getAllReferences($a_id)
get all reference ids of object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getList()

static ilSearchAutoComplete::getList (   $a_str)
static

Get completion list.

Definition at line 62 of file class.ilSearchAutoComplete.php.

References $DIC, $i, $ilDB, $l, $list, $result, checkObjectPermission(), ilJsonUtil\encode(), and ilSearchSettings\getInstance().

Referenced by ilSearchGUI\autoComplete(), and ilSearchBaseGUI\autoComplete().

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  }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$result
global $DIC
Definition: saml.php:7
static encode($mixed, $suppress_native=false)
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLuceneList()

static ilSearchAutoComplete::getLuceneList (   $a_str)
static

Performs better than standard like search on huge installations.

Definition at line 16 of file class.ilSearchAutoComplete.php.

References $i, $list, $res, $result, ilObject\_lookupTitle(), ilJsonUtil\encode(), ilSearchSettings\getInstance(), ilLuceneSearcher\getInstance(), and ilLuceneSearcher\TYPE_STANDARD.

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  }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$result
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static _lookupTitle($a_id)
lookup object title
static encode($mixed, $suppress_native=false)
foreach($_POST as $key=> $value) $res
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: