ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 148 of file class.ilSearchAutoComplete.php.

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 }
static _getAllReferences($a_id)
get all reference ids of object

References 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 (   $a_str)
static

Get completion list.

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

67 {
68 global $ilDB;
69
70 include_once './Services/Search/classes/class.ilSearchSettings.php';
71 if(ilSearchSettings::getInstance()->enabledLucene())
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', '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 {
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';
143 }
$result
global $l
Definition: afr.php:30
static encode($mixed, $suppress_native=false)
static checkObjectPermission($a_obj_id)
Checks read permission on obj id.
static getLuceneList($a_str)
Performs better than standard like search on huge installations.
global $ilDB

References $ilDB, $l, $result, checkObjectPermission(), ilJsonUtil\encode(), 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 (   $a_str)
static

Performs better than standard like search on huge installations.

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

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 }
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static _lookupTitle($a_id)
lookup object title

References $res, $result, ilObject\_lookupTitle(), ilJsonUtil\encode(), 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: