ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSearchResult Class Reference
+ Collaboration diagram for ilSearchResult:

Public Member Functions

 __construct ($a_user_id=0)
 Constructor @access public. More...
 
 setRequiredPermission ($a_permission)
 Set the required permission for the rbac checks in function 'filter()'. More...
 
 getRequiredPermission ()
 
 setUserId ($a_user_id)
 
 getUserId ()
 
 getEntries ()
 
 isLimitReached ()
 
 setMaxHits ($a_max_hits)
 
 getMaxHits ()
 
 isOffsetReached ($a_counter)
 Check if offset is reached. More...
 
 addEntry ($a_obj_id, $a_type, $found, $a_child_id=0)
 add search result entry Entries are stored with 'obj_id'. More...
 
 numEntries ()
 Check number of entries @access public. More...
 
 mergeEntries (&$result_obj)
 merge entries of this instance and another result object More...
 
 diffEntriesFromResult (&$result_obj)
 diff entries of this instance and another result object Used for search in results More...
 
 intersectEntries (&$result_obj)
 Build intersection of entries (all entries that are present in both result sets) More...
 
 addResult ($a_ref_id, $a_obj_id, $a_type)
 add search result Results are stored with 'ref_id'. More...
 
 getResults ()
 
 getResultIds ()
 get result ids More...
 
 getResultsByObjId ()
 
 getUniqueResults ()
 Get unique results. More...
 
 getResultsForPresentation ()
 
 getSubitemIds ()
 
 filter ($a_root_node, $check_and)
 Filter search result. More...
 
 filterResults ($a_root_node)
 Filter search area of result set @access public. More...
 
 save ($a_type=DEFAULT_SEARCH)
 Save search results. More...
 
 read ($a_type=DEFAULT_SEARCH)
 read search results More...
 
 __updateEntryChilds ($a_obj_id, $a_childs)
 Update childs for a specific entry. More...
 
 __updateResultChilds ($a_ref_id, $a_childs)
 Update childs for a specific result. More...
 
 __initSearchSettingsObject ()
 
 preventOverwritingMaxhits ($a_flag=null)
 If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearchSettingsObject() More...
 
 addObserver (&$a_class, $a_method)
 The observer is used to call functions for filtering result. More...
 
 callListeners ($a_ref_id, &$a_data)
 

Data Fields

 $permission = 'visible'
 
 $user_id
 
 $entries = array()
 
 $results = array()
 
 $observers = array()
 
 $ilias
 
 $ilAccess
 
 $limit_reached = false
 
 $result
 

Protected Member Functions

 initUserSearchCache ()
 Init user search cache. More...
 

Protected Attributes

 $search_cache = null
 
 $offset = 0
 
 $preventOverwritingMaxhits = false
 

Detailed Description

Definition at line 40 of file class.ilSearchResult.php.

Constructor & Destructor Documentation

◆ __construct()

ilSearchResult::__construct (   $a_user_id = 0)

Constructor @access public.

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

67 {
69
70 $this->ilAccess = $ilAccess;
71 if($a_user_id)
72 {
73 $this->user_id = $a_user_id;
74 }
75 else
76 {
77 $this->user_id = $ilUser->getId();
78 }
80 $this->initUserSearchCache();
81
82 $this->db = $ilDB;
83 }
initUserSearchCache()
Init user search cache.
global $ilDB
$ilUser
Definition: imgupload.php:18

References $ilAccess, $ilDB, $ilias, $ilUser, __initSearchSettingsObject(), and initUserSearchCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ __initSearchSettingsObject()

ilSearchResult::__initSearchSettingsObject ( )

Definition at line 551 of file class.ilSearchResult.php.

552 {
553 include_once 'Services/Search/classes/class.ilSearchSettings.php';
554
555 $this->search_settings = new ilSearchSettings();
556 if(!$this->preventOverwritingMaxhits())
557 $this->setMaxHits($this->search_settings->getMaxHits());
558 }
preventOverwritingMaxhits($a_flag=null)
If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearch...

References preventOverwritingMaxhits(), and setMaxHits().

Referenced by __construct().

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

◆ __updateEntryChilds()

ilSearchResult::__updateEntryChilds (   $a_obj_id,
  $a_childs 
)

Update childs for a specific entry.

Parameters
integerobject object_id
arrayarray of child ids. E.g 'pg', 'st' @access private

Definition at line 514 of file class.ilSearchResult.php.

515 {
516 if($this->entries[$a_obj_id] and is_array($a_childs))
517 {
518 foreach($a_childs as $child_id)
519 {
520 if($child_id)
521 {
522 $this->entries[$a_obj_id]['child'][$child_id] = $child_id;
523 }
524 }
525 return true;
526 }
527 return false;
528 }

Referenced by diffEntriesFromResult(), intersectEntries(), and mergeEntries().

+ Here is the caller graph for this function:

◆ __updateResultChilds()

ilSearchResult::__updateResultChilds (   $a_ref_id,
  $a_childs 
)

Update childs for a specific result.

Parameters
integerobject ref_id
arrayarray of child ids. E.g 'pg', 'st' @access private

Definition at line 536 of file class.ilSearchResult.php.

537 {
538 if($this->results[$a_ref_id] and is_array($a_childs))
539 {
540 foreach($a_childs as $child_id)
541 {
542 $this->results[$a_ref_id]['child'][$child_id] = $child_id;
543 }
544 return true;
545 }
546 return false;
547 }

Referenced by filter(), and filterResults().

+ Here is the caller graph for this function:

◆ addEntry()

ilSearchResult::addEntry (   $a_obj_id,
  $a_type,
  $found,
  $a_child_id = 0 
)

add search result entry Entries are stored with 'obj_id'.

This method is typically called to store db query results.

Parameters
integerobject object_id
stringobj_type 'lm' or 'crs' ...
arrayvalue position of query parser words in query string
integerchild id e.g id of page or chapter @access public

Definition at line 149 of file class.ilSearchResult.php.

150 {
151 // Create new entry if it not exists
152 if(!$this->entries[$a_obj_id])
153 {
154 $this->entries[$a_obj_id]['obj_id'] = $a_obj_id;
155 $this->entries[$a_obj_id]['type'] = $a_type;
156 $this->entries[$a_obj_id]['found'] = $found;
157
158 if($a_child_id and $a_child_id != $a_obj_id)
159 {
160 $this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
161 }
162 }
163 else
164 {
165 // replace or add child ('pg','st') id
166 if($a_child_id and $a_child_id != $a_obj_id)
167 {
168 $this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
169 }
170
171 // UPDATE FOUND
172 $counter = 0;
173 foreach($found as $position)
174 {
175 if($position)
176 {
177 $this->entries[$a_obj_id]['found'][$counter] = $position;
178 }
179 $counter++;
180 }
181 }
182 return true;
183 }
$counter
$a_type
Definition: workflow.php:93

References $a_type, and $counter.

Referenced by diffEntriesFromResult(), intersectEntries(), and mergeEntries().

+ Here is the caller graph for this function:

◆ addObserver()

ilSearchResult::addObserver ( $a_class,
  $a_method 
)

The observer is used to call functions for filtering result.

Every callback function should support the following parameters: array of ids. E.g: ref_id = 5,array(obj_id = 1,type = 'crs'), The function should return true or false.

Parameters
objectclass of callback function
stringname of callback method @access public

Definition at line 603 of file class.ilSearchResult.php.

604 {
605 $this->observers[] = array('class' => $a_class,
606 'method' => $a_method);
607 return true;
608 }

◆ addResult()

ilSearchResult::addResult (   $a_ref_id,
  $a_obj_id,
  $a_type 
)

add search result Results are stored with 'ref_id'.

This method is typically called after checking access of entries.

Parameters
integerref_id
integerobj_id
stringobj_type 'lm' or 'crs' ... @access public

Definition at line 273 of file class.ilSearchResult.php.

274 {
275 $this->results[$a_ref_id]['ref_id'] = $a_ref_id;
276 $this->results[$a_ref_id]['obj_id'] = $a_obj_id;
277 $this->results[$a_ref_id]['type'] = $a_type;
278 }

References $a_type.

Referenced by filter(), and filterResults().

+ Here is the caller graph for this function:

◆ callListeners()

ilSearchResult::callListeners (   $a_ref_id,
$a_data 
)

Definition at line 609 of file class.ilSearchResult.php.

610 {
611 foreach($this->observers as $observer)
612 {
613 $class =& $observer['class'];
614 $method = $observer['method'];
615
616 if(!$class->$method($a_ref_id,$a_data))
617 {
618 return false;
619 }
620 }
621 return true;
622 }

Referenced by filter().

+ Here is the caller graph for this function:

◆ diffEntriesFromResult()

ilSearchResult::diffEntriesFromResult ( $result_obj)

diff entries of this instance and another result object Used for search in results

Parameters
objectresult_obj @access public

Definition at line 218 of file class.ilSearchResult.php.

219 {
220 $new_entries = $this->getEntries();
221 $this->entries = array();
222
223 // Get all checked objects
224 foreach($this->search_cache->getCheckedItems() as $ref_id => $obj_id)
225 {
226 if(isset($new_entries[$obj_id]))
227 {
228 $this->addEntry($new_entries[$obj_id]['obj_id'],
229 $new_entries[$obj_id]['type'],
230 $new_entries[$obj_id]['found']);
231 $this->__updateEntryChilds($new_entries[$obj_id]['obj_id'],
232 $new_entries[$obj_id]['child']);
233 }
234 }
235 }
addEntry($a_obj_id, $a_type, $found, $a_child_id=0)
add search result entry Entries are stored with 'obj_id'.
__updateEntryChilds($a_obj_id, $a_childs)
Update childs for a specific entry.
$ref_id
Definition: sahs_server.php:39

References $ref_id, __updateEntryChilds(), addEntry(), and getEntries().

+ Here is the call graph for this function:

◆ filter()

ilSearchResult::filter (   $a_root_node,
  $check_and 
)

Filter search result.

Do RBAC checks.

Allows paging of results for referenced objects

@access public

Parameters
introot node id
boolcheck and boolean search
Returns
bool success status

Definition at line 367 of file class.ilSearchResult.php.

368 {
369 global $tree;
370
371 // get ref_ids and check access
372 $counter = 0;
373 $offset_counter = 0;
374 foreach($this->getEntries() as $entry)
375 {
376 // boolean and failed continue
377 if($check_and and in_array(0,$entry['found']))
378 {
379 continue;
380 }
381 // Types like role, rolt, user do not need rbac checks
382 $type = ilObject::_lookupType($entry['obj_id']);
383 if($type == 'rolt' or $type == 'usr' or $type == 'role')
384 {
385 if($this->callListeners($entry['obj_id'],$entry))
386 {
387 $this->addResult($entry['obj_id'],$entry['obj_id'],$type);
388 $counter += count($entry['child']);
389 // Stop if maximum of hits is reached
390 if(++$counter > $this->getMaxHits())
391 {
392 $this->limit_reached = true;
393 return true;
394 }
395 }
396 continue;
397 }
398 // Check referenced objects
399 foreach(ilObject::_getAllReferences($entry['obj_id']) as $ref_id)
400 {
401 // Failed check: if ref id check is failed by previous search
402 if($this->search_cache->isFailed($ref_id))
403 {
404 continue;
405 }
406 // Offset check
407 if($this->search_cache->isChecked($ref_id) and !$this->isOffsetReached($offset_counter))
408 {
409 ++$offset_counter;
410 continue;
411 }
412
413 if(!$this->callListeners($ref_id, $entry))
414 {
415 continue;
416 }
417
418
419
420 // RBAC check
421 $type = ilObject::_lookupType($ref_id, true);
422 if($this->ilAccess->checkAccessOfUser($this->getUserId(),
423 $this->getRequiredPermission(),
424 '',
425 $ref_id,
426 $type,
427 $entry['obj_id']))
428 {
429 if($a_root_node == ROOT_FOLDER_ID or $tree->isGrandChild($a_root_node,$ref_id))
430 {
431 // Call listeners
432 #if($this->callListeners($ref_id,$entry))
433 if(1)
434 {
435 $this->addResult($ref_id,$entry['obj_id'],$type);
436 $this->search_cache->appendToChecked($ref_id,$entry['obj_id']);
437 $this->__updateResultChilds($ref_id,$entry['child']);
438
439 $counter++;
440 $offset_counter++;
441 // Stop if maximum of hits is reached
442
443 if($counter >= $this->getMaxHits())
444 {
445 $this->limit_reached = true;
446 $this->search_cache->setResults($this->results);
447 return true;
448 }
449 }
450 }
451 continue;
452 }
453 $this->search_cache->appendToFailed($ref_id);
454 }
455 }
456 $this->search_cache->setResults($this->results);
457 return false;
458 }
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
callListeners($a_ref_id, &$a_data)
addResult($a_ref_id, $a_obj_id, $a_type)
add search result Results are stored with 'ref_id'.
__updateResultChilds($a_ref_id, $a_childs)
Update childs for a specific result.

References $counter, $ref_id, __updateResultChilds(), ilObject\_getAllReferences(), ilObject\_lookupType(), addResult(), callListeners(), getEntries(), and getMaxHits().

+ Here is the call graph for this function:

◆ filterResults()

ilSearchResult::filterResults (   $a_root_node)

Filter search area of result set @access public.

Definition at line 465 of file class.ilSearchResult.php.

466 {
467 global $tree;
468
469 $tmp_results = $this->getResults();
470 $this->results = array();
471 foreach($tmp_results as $result)
472 {
473 if($tree->isGrandChild($a_root_node,$result['ref_id']) and $tree->isInTree($result['ref_id']))
474 {
475 $this->addResult($result['ref_id'],$result['obj_id'],$result['type']);
476 $this->__updateResultChilds($result['ref_id'],$result['child']);
477 }
478 }
479
480 return true;
481 }

References $result, __updateResultChilds(), addResult(), and getResults().

+ Here is the call graph for this function:

◆ getEntries()

ilSearchResult::getEntries ( )

Definition at line 108 of file class.ilSearchResult.php.

109 {
110 return $this->entries ? $this->entries : array();
111 }

Referenced by diffEntriesFromResult(), filter(), intersectEntries(), and numEntries().

+ Here is the caller graph for this function:

◆ getMaxHits()

ilSearchResult::getMaxHits ( )

Definition at line 122 of file class.ilSearchResult.php.

123 {
124 return $this->max_hits;
125 }

Referenced by filter(), and initUserSearchCache().

+ Here is the caller graph for this function:

◆ getRequiredPermission()

ilSearchResult::getRequiredPermission ( )

Definition at line 93 of file class.ilSearchResult.php.

94 {
95 return $this->permission;
96 }

References $permission.

◆ getResultIds()

ilSearchResult::getResultIds ( )

get result ids

@access public

Returns
array result ids

Definition at line 291 of file class.ilSearchResult.php.

292 {
293 foreach($this->getResults() as $id => $tmp)
294 {
295 $ids[] = $id;
296 }
297 return $ids ? $ids : array();
298 }

References getResults().

+ Here is the call graph for this function:

◆ getResults()

ilSearchResult::getResults ( )

Definition at line 280 of file class.ilSearchResult.php.

281 {
282 return $this->results ? $this->results : array();
283 }

Referenced by filterResults(), getResultIds(), getResultsByObjId(), getResultsForPresentation(), and getSubitemIds().

+ Here is the caller graph for this function:

◆ getResultsByObjId()

ilSearchResult::getResultsByObjId ( )

Definition at line 300 of file class.ilSearchResult.php.

301 {
302 $tmp_res = array();
303 foreach($this->getResults() as $ref_id => $res_data)
304 {
305 $tmp_res[$res_data['obj_id']][] = $ref_id;
306 }
307 return $tmp_res ? $tmp_res : array();
308 }

References $ref_id, and getResults().

+ Here is the call graph for this function:

◆ getResultsForPresentation()

ilSearchResult::getResultsForPresentation ( )

Definition at line 332 of file class.ilSearchResult.php.

333 {
334 $res = array();
335
336 foreach($this->getResults() as $result)
337 {
338 $res[$result['ref_id']] = $result['obj_id'];
339 }
340 return $res;
341 }

References $res, $result, and getResults().

+ Here is the call graph for this function:

◆ getSubitemIds()

ilSearchResult::getSubitemIds ( )

Definition at line 343 of file class.ilSearchResult.php.

344 {
345 $res = array();
346 foreach($this->getResults() as $row)
347 {
348 $res[$row['obj_id']] = $row['child'];
349 }
350 return $res ? $res : array();
351 }

References $res, $row, and getResults().

+ Here is the call graph for this function:

◆ getUniqueResults()

ilSearchResult::getUniqueResults ( )

Get unique results.

Return an array of obj_id (No multiple results for references) Results are stored with 'ref_id'. This method is typically called after checking access of entries. @access public

Definition at line 317 of file class.ilSearchResult.php.

318 {
319 $obj_ids = array();
320 foreach($this->results as $result)
321 {
322 if(in_array($result['obj_id'],$obj_ids))
323 {
324 continue;
325 }
326 $obj_ids[] = $result['obj_id'];
327 $objects[] = $result;
328 }
329 return $objects ? $objects : array();
330 }

References $result.

◆ getUserId()

ilSearchResult::getUserId ( )

Definition at line 103 of file class.ilSearchResult.php.

104 {
105 return $this->user_id;
106 }

References $user_id.

Referenced by initUserSearchCache().

+ Here is the caller graph for this function:

◆ initUserSearchCache()

ilSearchResult::initUserSearchCache ( )
protected

Init user search cache.

@access private

Definition at line 566 of file class.ilSearchResult.php.

567 {
568 include_once('Services/Search/classes/class.ilUserSearchCache.php');
569 $this->search_cache = ilUserSearchCache::_getInstance($this->getUserId());
570 $this->offset = $this->getMaxHits() * ($this->search_cache->getResultPageNumber() - 1) ;
571 }
static _getInstance($a_usr_id)
Get singleton instance.

References ilUserSearchCache\_getInstance(), getMaxHits(), and getUserId().

Referenced by __construct().

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

◆ intersectEntries()

ilSearchResult::intersectEntries ( $result_obj)

Build intersection of entries (all entries that are present in both result sets)

Parameters
objectresult_obj @access public

Definition at line 243 of file class.ilSearchResult.php.

244 {
245 $new_entries = $this->getEntries();
246 $this->entries = array();
247
248 foreach($result_obj->getEntries() as $entry)
249 {
250 $obj_id = $entry['obj_id'];
251 if(isset($new_entries[$obj_id]))
252 {
253 $this->addEntry($new_entries[$obj_id]['obj_id'],
254 $new_entries[$obj_id]['type'],
255 $new_entries[$obj_id]['found']);
256
257 $this->__updateEntryChilds($new_entries[$obj_id]['obj_id'],
258 $new_entries[$obj_id]['child']);
259 }
260 }
261 }

References __updateEntryChilds(), addEntry(), and getEntries().

+ Here is the call graph for this function:

◆ isLimitReached()

ilSearchResult::isLimitReached ( )

Definition at line 113 of file class.ilSearchResult.php.

114 {
115 return $this->limit_reached ? true : false;
116 }

◆ isOffsetReached()

ilSearchResult::isOffsetReached (   $a_counter)

Check if offset is reached.

@access public

Parameters
intcurrent counter of result
Returns
bool reached or not

Definition at line 134 of file class.ilSearchResult.php.

135 {
136 return ($a_counter < $this->offset) ? false : true;
137 }

◆ mergeEntries()

ilSearchResult::mergeEntries ( $result_obj)

merge entries of this instance and another result object

Parameters
objectresult_obj @access public

Definition at line 201 of file class.ilSearchResult.php.

202 {
203 foreach($result_obj->getEntries() as $entry)
204 {
205 $this->addEntry($entry['obj_id'],$entry['type'],$entry['found']);
206 $this->__updateEntryChilds($entry['obj_id'],$entry['child']);
207 }
208 return true;
209 }

References __updateEntryChilds(), and addEntry().

+ Here is the call graph for this function:

◆ numEntries()

ilSearchResult::numEntries ( )

Check number of entries @access public.

Definition at line 190 of file class.ilSearchResult.php.

191 {
192 return count($this->getEntries());
193 }

References getEntries().

+ Here is the call graph for this function:

◆ preventOverwritingMaxhits()

ilSearchResult::preventOverwritingMaxhits (   $a_flag = null)

If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearchSettingsObject()

@access public

Parameters
boolean$a_flagtrue or false to set the flag or leave blank to get the status of the flag @returmn boolean if called without parameter the status of the flag will be returned, otherwise $this

Definition at line 582 of file class.ilSearchResult.php.

583 {
584 if(null === $a_flag)
585 {
587 }
588
589 $this->preventOverwritingMaxhits = $a_flag;
590
591 return $this;
592 }

References $preventOverwritingMaxhits, and preventOverwritingMaxhits().

Referenced by __initSearchSettingsObject(), and preventOverwritingMaxhits().

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

◆ read()

ilSearchResult::read (   $a_type = DEFAULT_SEARCH)

read search results

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH @access public

Definition at line 501 of file class.ilSearchResult.php.

502 {
503 $this->results = $this->search_cache->getResults();
504 }

◆ save()

ilSearchResult::save (   $a_type = DEFAULT_SEARCH)

Save search results.

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH @access public

Definition at line 490 of file class.ilSearchResult.php.

491 {
492 $this->search_cache->save();
493 return false;
494 }

◆ setMaxHits()

ilSearchResult::setMaxHits (   $a_max_hits)

Definition at line 118 of file class.ilSearchResult.php.

119 {
120 $this->max_hits = $a_max_hits;
121 }

Referenced by __initSearchSettingsObject().

+ Here is the caller graph for this function:

◆ setRequiredPermission()

ilSearchResult::setRequiredPermission (   $a_permission)

Set the required permission for the rbac checks in function 'filter()'.

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

89 {
90 $this->permission = $a_permission;
91 }

◆ setUserId()

ilSearchResult::setUserId (   $a_user_id)

Definition at line 99 of file class.ilSearchResult.php.

100 {
101 $this->user_id = $a_user_id;
102 }

Field Documentation

◆ $entries

ilSearchResult::$entries = array()

Definition at line 45 of file class.ilSearchResult.php.

◆ $ilAccess

ilSearchResult::$ilAccess

Definition at line 54 of file class.ilSearchResult.php.

Referenced by __construct().

◆ $ilias

ilSearchResult::$ilias

Definition at line 53 of file class.ilSearchResult.php.

Referenced by __construct().

◆ $limit_reached

ilSearchResult::$limit_reached = false

Definition at line 57 of file class.ilSearchResult.php.

◆ $observers

ilSearchResult::$observers = array()

Definition at line 47 of file class.ilSearchResult.php.

◆ $offset

ilSearchResult::$offset = 0
protected

Definition at line 50 of file class.ilSearchResult.php.

◆ $permission

ilSearchResult::$permission = 'visible'

Definition at line 42 of file class.ilSearchResult.php.

Referenced by getRequiredPermission().

◆ $preventOverwritingMaxhits

ilSearchResult::$preventOverwritingMaxhits = false
protected

Definition at line 60 of file class.ilSearchResult.php.

Referenced by preventOverwritingMaxhits().

◆ $result

ilSearchResult::$result

◆ $results

ilSearchResult::$results = array()

Definition at line 46 of file class.ilSearchResult.php.

◆ $search_cache

ilSearchResult::$search_cache = null
protected

Definition at line 49 of file class.ilSearchResult.php.

◆ $user_id

ilSearchResult::$user_id

Definition at line 44 of file class.ilSearchResult.php.

Referenced by getUserId().


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