ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilSearchAutoComplete Class Reference

Search Auto Completion Application Class. More...

+ Collaboration diagram for ilSearchAutoComplete:

Static Public Member Functions

static getLuceneList (string $a_str)
 
static getList (string $a_str)
 
static checkObjectPermission (int $a_obj_id)
 

Detailed Description

Search Auto Completion Application Class.

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

Member Function Documentation

◆ checkObjectPermission()

static ilSearchAutoComplete::checkObjectPermission ( int  $a_obj_id)
static

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

136 : bool
137 {
138 global $DIC;
139
140 $ilAccess = $DIC->access();
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 }
static _getAllReferences(int $id)
get all reference ids for object ID
global $DIC
Definition: shib_login.php:26

References $DIC, and ilObject\_getAllReferences().

Referenced by getList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getList()

static ilSearchAutoComplete::getList ( string  $a_str)
static

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

67 : string
68 {
69 global $DIC;
70
71 $ilDB = $DIC->database();
72
73 if (ilSearchSettings::getInstance()->enabledLucene()) {
74 return self::getLuceneList($a_str);
75 }
76
77
78 $a_str = str_replace('"', "", $a_str);
79
80 $settings = new ilSearchSettings();
81
82 $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
83 'chat', 'webr','mcst','sess','pg','st','term','wiki', 'copa');
84
85 $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
86 . $ilDB->like('title', 'text', $a_str . "%") . " AND "
87 . $ilDB->in('type', $object_types, false, 'text') . " ORDER BY title");
88 $max = ($settings->getAutoCompleteLength() > 0)
89 ? $settings->getAutoCompleteLength()
90 : 10;
91
92 $cnt = 0;
93 $list = array();
94 $checked = array();
95 $lim = "";
96 while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
97 if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0) {
98 $rec["title"] = '"' . $rec["title"] . '"';
99 }
100 if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked)) {
101 if (ilSearchAutoComplete::checkObjectPermission((int) $rec["obj_id"])) {
102 $list[] = $lim . $rec["title"];
103 $cnt++;
104 }
105 $checked[] = $rec["obj_id"];
106 }
107 }
108
109 $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
110 . $ilDB->like('keyword', 'text', $a_str . "%") . " AND "
111 . $ilDB->in('obj_type', $object_types, false, 'text') . " ORDER BY keyword");
112 while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
113 if (strpos($rec["keyword"], " ") > 0) {
114 $rec["keyword"] = '"' . $rec["keyword"] . '"';
115 }
116 if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked)) {
117 if (ilSearchAutoComplete::checkObjectPermission((int) $rec["rbac_id"])) {
118 $list[] = $lim . $rec["keyword"];
119 $cnt++;
120 }
121 }
122 $checked[] = $rec["rbac_id"];
123 }
124
125 $i = 0;
126 $result = array();
127 foreach ($list as $l) {
128 $result[$i] = new stdClass();
129 $result[$i]->value = $l;
130 $i++;
131 }
132
133 return json_encode($result, JSON_THROW_ON_ERROR);
134 }
static checkObjectPermission(int $a_obj_id)
static getLuceneList(string $a_str)

References $DIC, $ilDB, checkObjectPermission(), ilSearchSettings\getInstance(), and getLuceneList().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLuceneList()

static ilSearchAutoComplete::getLuceneList ( string  $a_str)
static

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

26 : string
27 {
28 $qp = new ilLuceneQueryParser('title:' . $a_str . '*');
29 $qp->parse();
30
31 $searcher = ilLuceneSearcher::getInstance($qp);
32 $searcher->setType(ilLuceneSearcher::TYPE_STANDARD);
33 $searcher->search();
34
35 $res = $searcher->getResult()->getCandidates();
36
37 $max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength() ?
38 ilSearchSettings::getInstance()->getAutoCompleteLength() :
39 10;
40
41
42 $list = array();
43 $num_entries = 0;
44 foreach ($res as $res_obj_id) {
45 if (self::checkObjectPermission($res_obj_id)) {
46 $list[] = ilObject::_lookupTitle($res_obj_id);
47 $num_entries++;
48 }
49 if ($num_entries >= $max_entries) {
50 break;
51 }
52 }
53
54 $i = 0;
55 $result = array();
56 foreach ($list as $entry) {
57 $result[$i] = new stdClass();
58 $result[$i]->value = '"' . $entry . '"';
59 $i++;
60 }
61
62 return json_encode($result, JSON_THROW_ON_ERROR);
63 }
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static _lookupTitle(int $obj_id)
$res
Definition: ltiservices.php:69

References $res, ilObject\_lookupTitle(), ilSearchSettings\getInstance(), ilLuceneSearcher\getInstance(), and ilLuceneSearcher\TYPE_STANDARD.

Referenced by getList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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