ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSearch Class Reference

search More...

+ Collaboration diagram for ilSearch:

Public Member Functions

 __construct ($a_user_id=0, $a_read=false)
 Constructor public. More...
 
 setSearchString ($a_search_str)
 
 setCombination ($a_combination)
 
 setSearchFor ($a_search_for)
 
 setSearchIn ($a_search_in)
 
 setResult ($a_result)
 
 setSearchType ($a_type)
 
 setPerformUpdate ($a_value)
 
 setEmptySearch ($a_value)
 
 setMinWordLength ($a_min_word_length)
 
 getMinWordLength ()
 
 getUserId ()
 
 getSearchString ()
 
 getCombination ()
 
 getSearchFor ()
 
 getSearchIn ()
 
 getSearchInByType ($a_type)
 
 getResults ()
 
 getResultByType ($a_type)
 
 getSearchType ()
 
 getPerformUpdate ()
 
 getEmptySearch ()
 
 getNumberOfResults ()
 
 validate (&$message)
 
 performSearch ()
 
 __parseSearchString ()
 
 __updateDBResult ()
 
 __readDBResult ()
 
 __checkAccess ($a_results, $a_type)
 
 __validateResults ()
 
 __prepareWord ($a_word)
 

Data Fields

 $ilias
 
 $lng
 
 $rbacsystem
 
 $user_id
 
 $search_string
 
 $parsed_str
 
 $combination
 
 $min_word_length = 3
 
 $search_for
 
 $search_in
 
 $search_type
 
 $result
 
 $perform_update
 
 $read_db_result
 
 $allow_empty_search
 

Protected Member Functions

 performUserSearch ()
 perform a search for users More...
 
 performObjectSearch ($a_type)
 perform object search More...
 
 performRoleSearch ()
 
 initQueryParser ()
 init query parser More...
 

Protected Attributes

 $qp = null
 

Detailed Description

search

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id$

Definition at line 14 of file class.ilSearch.php.

Constructor & Destructor Documentation

◆ __construct()

ilSearch::__construct (   $a_user_id = 0,
  $a_read = false 
)

Constructor public.

Definition at line 43 of file class.ilSearch.php.

References $ilias, $lng, $rbacsystem, setEmptySearch(), and setPerformUpdate().

44  {
45  global $ilias,$rbacsystem,$lng;
46 
47  // Initiate variables
48  $this->ilias =& $ilias;
49  $this->lng =& $lng;
50  $this->lng->loadLanguageModule("search");
51  $this->rbacsystem =& $rbacsystem;
52  $this->user_id = $a_user_id;
53 
54  $this->setPerformUpdate(true);
55  $this->setEmptySearch(false);
56  $this->read_db_result = $a_read;
57 
58  // READ OLD SEARCH RESULTS FROM DATABASE
59  #$this->__readDBResult();
60  }
setEmptySearch($a_value)
redirection script todo: (a better solution should control the processing via a xml file) ...
setPerformUpdate($a_value)
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkAccess()

ilSearch::__checkAccess (   $a_results,
  $a_type 
)

Definition at line 349 of file class.ilSearch.php.

References $result, and array.

Referenced by __validateResults().

350  {
351  global $ilAccess;
352 
353  if (is_array($a_results))
354  {
355  foreach ($a_results as $result)
356  {
357  if($ilAccess->checkAccess('read','',$result['id']))
358  {
359  $checked_result[] = $result;
360  break;
361  }
362  }
363  }
364  return $checked_result ? $checked_result : array();
365  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ __parseSearchString()

ilSearch::__parseSearchString ( )

Definition at line 242 of file class.ilSearch.php.

References __prepareWord(), array, getCombination(), and getSearchString().

243  {
244  $tmp_arr = explode(" ",$this->getSearchString());
245  $this->parsed_str["and"] = $this->parsed_str["or"] = $this->parsed_str["not"] = array();
246 
247  foreach ($tmp_arr as $word)
248  {
249  #$word = trim($word);
250  $word = $this->__prepareWord($word);
251  if ($word)
252  {
253  if (substr($word,0,1) == '+')
254  {
255  $this->parsed_str["all"][] = substr($word,1);
256  $this->parsed_str["and"][] = substr($word,1);
257  continue;
258  }
259 
260  if (substr($word,0,1) == '-')
261  {
262  // better parsed_str["allmost_all"] ;-)
263  #$this->parsed_str["all"][] = substr($word,1);
264  $this->parsed_str["not"][] = substr($word,1);
265  continue;
266  }
267 
268  if ($this->getCombination() == 'and')
269  {
270  $this->parsed_str["all"][] = $word;
271  $this->parsed_str["and"][] = $word;
272  continue;
273  }
274 
275  if ($this->getCombination() == 'or')
276  {
277  $this->parsed_str["all"][] = $word;
278  $this->parsed_str["or"][] = $word;
279  continue;
280  }
281  }
282  }
283  }
__prepareWord($a_word)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ __prepareWord()

ilSearch::__prepareWord (   $a_word)

Definition at line 457 of file class.ilSearch.php.

Referenced by __parseSearchString().

458  {
459  $word = trim($a_word);
460 
461  if(!preg_match('/\*/',$word))
462  {
463  return '%'.$word.'%';
464  }
465  if(preg_match('/^\*/',$word))
466  {
467  return str_replace('*','%',$word);
468  }
469  else
470  {
471  return '% '.str_replace('*','%',$word);
472  }
473  }
+ Here is the caller graph for this function:

◆ __readDBResult()

ilSearch::__readDBResult ( )

Definition at line 311 of file class.ilSearch.php.

References $ilDB, $query, $res, $row, __updateDBResult(), __validateResults(), array, ilDBConstants\FETCHMODE_OBJECT, getUserId(), and setResult().

312  {
313  global $ilDB;
314 
315  if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID and $this->read_db_result)
316  {
317  $query = "SELECT search_result FROM usr_search ".
318  "WHERE usr_id = ".$ilDB->quote($this->getUserId() ,'integer');
319 
320 
321  $res = $ilDB->query($query);
322  if ($res->numRows())
323  {
325  $this->setResult(unserialize(stripslashes($row->search_result)));
326  }
327  else
328  {
329  $this->setResult(array("usr" => array(),
330  "grp" => array(),
331  "lm" => array(),
332  "dbk" => array()));
333  }
334  }
335  else
336  {
337  $this->setResult(array("usr" => array(),
338  "grp" => array(),
339  "lm" => array(),
340  "dbk" => array()));
341  }
342 
343  $this->__validateResults();
344  $this->__updateDBResult();
345  return true;
346  }
setResult($a_result)
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ __updateDBResult()

ilSearch::__updateDBResult ( )

Definition at line 285 of file class.ilSearch.php.

References $ilDB, array, getResults(), and getUserId().

Referenced by __readDBResult(), and performSearch().

286  {
287  global $ilDB;
288 
289  if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID)
290  {
291  $ilDB->manipulate("DELETE FROM usr_search ".
292  "WHERE usr_id = ".$ilDB->quote($this->getUserId() ,'integer')." ".
293  "AND search_type = 0 ");
294 
295  $ilDB->insert('usr_search',array(
296  'usr_id' => array('integer',$this->getUserId()),
297  'search_result' => array('clob',serialize($this->getResults())),
298  'checked' => array('clob',serialize(array())),
299  'failed' => array('clob',serialize(array())),
300  'page' => array('integer',0),
301  'search_type' => array('integer',0),
302  'query' => array('text',''),
303  'root' => array('integer',ROOT_FOLDER_ID)));
304 
305  return true;
306  }
307 
308  return false;
309  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __validateResults()

ilSearch::__validateResults ( )

Definition at line 368 of file class.ilSearch.php.

References $data, __checkAccess(), array, ilObjectFactory\getInstanceByObjId(), and setResult().

Referenced by __readDBResult(), and performSearch().

369  {
370  global $tree;
371 
372  $new_result = array();
373 
374 
375  // check lm meta
376 
377  $this->result['lm']['meta'] = $this->__checkAccess($this->result['lm']['meta'],'lm');
378  if(is_array($this->result['lm']['meta']))
379  {
380  foreach($this->result['lm']['meta'] as $data)
381  {
382  if($tree->isInTree($data['id']))
383  {
384  $new_result['lm']['meta'][] = $data;
385  }
386  }
387  }
388  $this->result['lm']['content'] = $this->__checkAccess($this->result['lm']['content'],'lm');
389  if(is_array($this->result['lm']['content']))
390  {
391  foreach($this->result['lm']['content'] as $data)
392  {
393  if($tree->isInTree($data['id']))
394  {
395  $new_result['lm']['content'][] = $data;
396  }
397  }
398  }
399  $this->result['dbk']['meta'] = $this->__checkAccess($this->result['dbk']['meta'],'dbk');
400  if(is_array($this->result['dbk']['meta']))
401  {
402  foreach($this->result['dbk']['meta'] as $data)
403  {
404  if($tree->isInTree($data['id']))
405  {
406  $new_result['dbk']['meta'][] = $data;
407  }
408  }
409  }
410  $this->result['dbk']['content'] = $this->__checkAccess($this->result['dbk']['content'],'dbk');
411  if(is_array($this->result['dbk']['content']))
412  {
413  foreach($this->result['dbk']['content'] as $data)
414  {
415  if($tree->isInTree($data['id']))
416  {
417  $new_result['dbk']['content'][] = $data;
418  }
419  }
420  }
421  $this->result['grp'] = $this->__checkAccess($this->result['grp'],'grp');
422  if(is_array($this->result['grp']))
423  {
424  foreach($this->result['grp'] as $data)
425  {
426  if($tree->isInTree($data['id']))
427  {
428  $new_result['grp'][] = $data;
429  }
430  }
431  }
432  if(is_array($this->result['usr']))
433  {
434  foreach($this->result['usr'] as $user)
435  {
436  if($tmp_obj =& ilObjectFactory::getInstanceByObjId($user['id'],false))
437  {
438  $new_result['usr'][] = $user;
439  }
440  }
441  }
442  if(is_array($this->result['role']))
443  {
444  foreach($this->result['role'] as $user)
445  {
446  if($tmp_obj =& ilObjectFactory::getInstanceByObjId($user['id'],false))
447  {
448  $new_result['role'][] = $user;
449  }
450  }
451  }
452  $this->setResult($new_result);
453 
454  return true;
455  }
__checkAccess($a_results, $a_type)
setResult($a_result)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCombination()

ilSearch::getCombination ( )

Definition at line 115 of file class.ilSearch.php.

Referenced by __parseSearchString(), initQueryParser(), and performObjectSearch().

116  {
117  return $this->combination ? $this->combination : "or";
118  }
+ Here is the caller graph for this function:

◆ getEmptySearch()

ilSearch::getEmptySearch ( )

Definition at line 154 of file class.ilSearch.php.

References $allow_empty_search.

155  {
157  }

◆ getMinWordLength()

ilSearch::getMinWordLength ( )

Definition at line 101 of file class.ilSearch.php.

References $min_word_length.

Referenced by initQueryParser().

102  {
103  return $this->min_word_length;
104  }
+ Here is the caller graph for this function:

◆ getNumberOfResults()

ilSearch::getNumberOfResults ( )

Definition at line 161 of file class.ilSearch.php.

References getResultByType().

162  {
163  $number = count($this->getResultByType("usr")) + count($this->getResultByType("grp")) + count($this->getResultByType("role"));
164 
165  $tmp_res = $this->getResultByType("dbk");
166  $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
167 
168  $tmp_res = $this->getResultByType("lm");
169  $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
170 
171  return $number;
172  }
getResultByType($a_type)
+ Here is the call graph for this function:

◆ getPerformUpdate()

ilSearch::getPerformUpdate ( )

Definition at line 150 of file class.ilSearch.php.

References $perform_update.

Referenced by performSearch().

151  {
152  return $this->perform_update;
153  }
+ Here is the caller graph for this function:

◆ getResultByType()

ilSearch::getResultByType (   $a_type)

Definition at line 142 of file class.ilSearch.php.

References $a_type, and array.

Referenced by getNumberOfResults().

143  {
144  return $this->result[$a_type] ? $this->result[$a_type] : array();
145  }
$a_type
Definition: workflow.php:93
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getResults()

ilSearch::getResults ( )

Definition at line 138 of file class.ilSearch.php.

References array.

Referenced by __updateDBResult().

139  {
140  return $this->result ? $this->result : array();
141  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getSearchFor()

ilSearch::getSearchFor ( )

Definition at line 119 of file class.ilSearch.php.

References array.

Referenced by performSearch().

120  {
121  return $this->search_for ? $this->search_for : array();
122  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getSearchIn()

ilSearch::getSearchIn ( )

Definition at line 123 of file class.ilSearch.php.

References array.

124  {
125  return $this->search_in ? $this->search_in : array();
126  }
Create styles array
The data for the language used.

◆ getSearchInByType()

ilSearch::getSearchInByType (   $a_type)

Definition at line 127 of file class.ilSearch.php.

References $a_type.

128  {
129  if($a_type == 'lm' or $a_type == 'dbk')
130  {
131  return $this->search_in[$a_type];
132  }
133  else
134  {
135  return false;
136  }
137  }
$a_type
Definition: workflow.php:93

◆ getSearchString()

ilSearch::getSearchString ( )

Definition at line 111 of file class.ilSearch.php.

References $search_string.

Referenced by __parseSearchString(), and initQueryParser().

112  {
113  return $this->search_string;
114  }
+ Here is the caller graph for this function:

◆ getSearchType()

ilSearch::getSearchType ( )

Definition at line 146 of file class.ilSearch.php.

References $search_type.

147  {
148  return $this->search_type;
149  }

◆ getUserId()

ilSearch::getUserId ( )

Definition at line 107 of file class.ilSearch.php.

References $user_id.

Referenced by __readDBResult(), __updateDBResult(), and performUserSearch().

108  {
109  return $this->user_id;
110  }
+ Here is the caller graph for this function:

◆ initQueryParser()

ilSearch::initQueryParser ( )
protected

init query parser

Returns

Definition at line 548 of file class.ilSearch.php.

References getCombination(), getMinWordLength(), getSearchString(), QP_COMBINATION_AND, and QP_COMBINATION_OR.

Referenced by performSearch(), and validate().

549  {
550  if($this->qp)
551  {
552  return true;
553  }
554 
555  $this->qp = new ilQueryParser($this->getSearchString());
556  $this->qp->setCombination($this->getCombination() == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
557  $this->qp->setMinWordLength($this->getMinWordLength());
558  $this->qp->parse();
559  }
const QP_COMBINATION_OR
const QP_COMBINATION_AND
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performObjectSearch()

ilSearch::performObjectSearch (   $a_type)
protected

perform object search

Returns

Definition at line 507 of file class.ilSearch.php.

References $a_type, $counter, $res, array, and getCombination().

Referenced by performSearch().

508  {
509  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
510  $object_search = new ilLikeObjectSearch($this->qp);
511  $object_search->setFilter(array($a_type));
512  $res = $object_search->performSearch();
513  $res->filter(ROOT_FOLDER_ID,$this->getCombination());
514 
515  $counter = 0;
516  foreach($res->getResultIds() as $id)
517  {
518  $objs[$counter++]['id'] = $id;
519  }
520  return $objs ? $objs : array();
521  }
$counter
$a_type
Definition: workflow.php:93
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performRoleSearch()

ilSearch::performRoleSearch ( )
protected
Parameters

Definition at line 528 of file class.ilSearch.php.

References $data, $res, and array.

Referenced by performSearch().

529  {
530  // Perform like search
531  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
532  $object_search = new ilLikeObjectSearch($this->qp);
533  $object_search->setFilter(array('role'));
534 
535  $res = $object_search->performSearch();
536  foreach($res->getEntries() as $id => $data)
537  {
538  $tmp['id'] = $id;
539  $roles[] = $tmp;
540  }
541  return $roles ? $roles : array();
542  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ performSearch()

ilSearch::performSearch ( )

Definition at line 186 of file class.ilSearch.php.

References $ilBench, __updateDBResult(), __validateResults(), array, getPerformUpdate(), getSearchFor(), initQueryParser(), performObjectSearch(), performRoleSearch(), performUserSearch(), and setResult().

187  {
188  global $objDefinition, $ilBench;
189 
190  $ilBench->start("Search", "performSearch");
191 
192  $this->initQueryParser();
193 
194  $result = array("usr" => array(),
195  "grp" => array(),
196  "lm" => array(),
197  "dbk" => array(),
198  "role"=> array());
199 
200  foreach($this->getSearchFor() as $obj_type)
201  {
202  switch($obj_type)
203  {
204  case "usr":
205  $result['usr'] = $this->performUserSearch();
206  break;
207 
208  case "grp":
209  $result['grp'] = $this->performObjectSearch('grp');
210  break;
211 
212  case "lm":
213  $result['lm'] = $this->performObjectSearch('lm');
214  break;
215 
216  case "dbk":
217  $result['dbk'] = $this->performObjectSearch('dbk');
218  break;
219 
220  case "role":
221  $result['role'] = $this->performRoleSearch();
222  break;
223  }
224  }
225 
226  $this->setResult($result);
227  $this->__validateResults();
228 
229  if ($this->getPerformUpdate())
230  {
231  $this->__updateDBResult();
232  }
233 
234  $ilBench->stop("Search", "performSearch");
235 
236  return true;
237  }
performUserSearch()
perform a search for users
setResult($a_result)
performObjectSearch($a_type)
perform object search
Create styles array
The data for the language used.
global $ilBench
Definition: ilias.php:18
initQueryParser()
init query parser
+ Here is the call graph for this function:

◆ performUserSearch()

ilSearch::performUserSearch ( )
protected

perform a search for users

Returns

Definition at line 479 of file class.ilSearch.php.

References $data, $res, ilObjectSearchFactory\_getUserSearchInstance(), array, and getUserId().

Referenced by performSearch().

480  {
481  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
482 
483  $user_search = ilObjectSearchFactory::_getUserSearchInstance($this->qp);
484  $res = new ilSearchResult($this->getUserId());
485 
486  foreach(array("login","firstname","lastname","title",
487  "email","institution","street","city","zipcode","country","phone_home","fax") as $field)
488  {
489  $user_search->setFields(array($field));
490  $tmp_res = $user_search->performSearch();
491 
492  $res->mergeEntries($tmp_res);
493  }
494 
495  foreach($res->getEntries() as $id => $data)
496  {
497  $tmp['id'] = $id;
498  $users[] = $tmp;
499  }
500  return $users ? $users : array();
501  }
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCombination()

ilSearch::setCombination (   $a_combination)

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

68  {
69  // 'and' or 'or'
70  $this->combination = $a_combination;
71  }

◆ setEmptySearch()

ilSearch::setEmptySearch (   $a_value)

Definition at line 92 of file class.ilSearch.php.

Referenced by __construct().

93  {
94  $this->allow_empty_search = $a_value;
95  }
+ Here is the caller graph for this function:

◆ setMinWordLength()

ilSearch::setMinWordLength (   $a_min_word_length)

Definition at line 97 of file class.ilSearch.php.

98  {
99  $this->min_word_length = $a_min_word_length;
100  }

◆ setPerformUpdate()

ilSearch::setPerformUpdate (   $a_value)

Definition at line 88 of file class.ilSearch.php.

Referenced by __construct().

89  {
90  $this->perform_update = $a_value;
91  }
+ Here is the caller graph for this function:

◆ setResult()

ilSearch::setResult (   $a_result)

Definition at line 80 of file class.ilSearch.php.

Referenced by __readDBResult(), __validateResults(), and performSearch().

81  {
82  $this->result = $a_result;
83  }
+ Here is the caller graph for this function:

◆ setSearchFor()

ilSearch::setSearchFor (   $a_search_for)

Definition at line 72 of file class.ilSearch.php.

73  {
74  $this->search_for = $a_search_for;
75  }

◆ setSearchIn()

ilSearch::setSearchIn (   $a_search_in)

Definition at line 76 of file class.ilSearch.php.

77  {
78  $this->search_in = $a_search_in;
79  }

◆ setSearchString()

ilSearch::setSearchString (   $a_search_str)

Definition at line 63 of file class.ilSearch.php.

64  {
65  $this->search_string = trim($a_search_str);
66  }

◆ setSearchType()

ilSearch::setSearchType (   $a_type)

Definition at line 84 of file class.ilSearch.php.

References $a_type.

85  {
86  $this->search_type = $a_type;
87  }
$a_type
Definition: workflow.php:93

◆ validate()

ilSearch::validate ( $message)

Definition at line 174 of file class.ilSearch.php.

References initQueryParser().

175  {
176  $this->initQueryParser();
177 
178  if(!$this->qp->validate())
179  {
180  $message = $this->qp->getMessage();
181  return false;
182  }
183  return true;
184  }
initQueryParser()
init query parser
+ Here is the call graph for this function:

Field Documentation

◆ $allow_empty_search

ilSearch::$allow_empty_search

Definition at line 38 of file class.ilSearch.php.

Referenced by getEmptySearch().

◆ $combination

ilSearch::$combination

Definition at line 29 of file class.ilSearch.php.

◆ $ilias

ilSearch::$ilias

Definition at line 23 of file class.ilSearch.php.

Referenced by __construct().

◆ $lng

ilSearch::$lng

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

Referenced by __construct().

◆ $min_word_length

ilSearch::$min_word_length = 3

Definition at line 30 of file class.ilSearch.php.

Referenced by getMinWordLength().

◆ $parsed_str

ilSearch::$parsed_str

Definition at line 28 of file class.ilSearch.php.

◆ $perform_update

ilSearch::$perform_update

Definition at line 35 of file class.ilSearch.php.

Referenced by getPerformUpdate().

◆ $qp

ilSearch::$qp = null
protected

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

◆ $rbacsystem

ilSearch::$rbacsystem

Definition at line 25 of file class.ilSearch.php.

Referenced by __construct().

◆ $read_db_result

ilSearch::$read_db_result

Definition at line 36 of file class.ilSearch.php.

◆ $result

ilSearch::$result

Definition at line 34 of file class.ilSearch.php.

Referenced by __checkAccess().

◆ $search_for

ilSearch::$search_for

Definition at line 31 of file class.ilSearch.php.

◆ $search_in

ilSearch::$search_in

Definition at line 32 of file class.ilSearch.php.

◆ $search_string

ilSearch::$search_string

Definition at line 27 of file class.ilSearch.php.

Referenced by getSearchString().

◆ $search_type

ilSearch::$search_type

Definition at line 33 of file class.ilSearch.php.

Referenced by getSearchType().

◆ $user_id

ilSearch::$user_id

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

Referenced by getUserId().


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