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

Validate Lucene search results Do access checks, create ref_ids from obj_ids... More...

+ Collaboration diagram for ilLuceneSearchResultFilter:

Public Member Functions

 addFilter (ilLuceneResultFilter $filter)
 add filter More...
 
 setCandidates ($a_ids)
 Set result ids. More...
 
 getCandidates ()
 get result ids More...
 
 getUserId ()
 Get user id. More...
 
 getRequiredPermission ()
 Get required permission. More...
 
 isLimitReached ()
 Check if search max hits is reached. More...
 
 getResultIds ()
 get filtered ids More...
 
 getResultObjIds ()
 get filtered ids More...
 
 getResults ()
 get results More...
 
 getMaxHits ()
 get max hits More...
 
 loadFromDb ()
 Load results from db. More...
 
 filter ()
 Filter search results. More...
 

Static Public Member Functions

static getInstance ($a_user_id)
 

Protected Member Functions

 __construct ($a_user_id)
 Singleton constructor. More...
 
 checkFilter ($a_ref_id)
 check appended filter More...
 
 append ($a_ref_id, $a_obj_id)
 Append to filtered results. More...
 
 isOffsetReached ($a_current_nr)
 Check if offset is reached. More...
 

Protected Attributes

 $user_id = null
 
 $result = array()
 
 $checked = array()
 
 $settings
 
 $cache
 
 $required_permission = 'visible'
 
 $limit_reached = false
 
 $offset = 0
 
 $filters = array()
 

Static Protected Attributes

static $instance = null
 

Detailed Description

Validate Lucene search results Do access checks, create ref_ids from obj_ids...

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

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

Constructor & Destructor Documentation

◆ __construct()

ilLuceneSearchResultFilter::__construct (   $a_user_id)
protected

Singleton constructor.

Parameters
int$a_usr_iduser id
Returns

Definition at line 55 of file class.ilLuceneSearchResultFilter.php.

References ilUserSearchCache\_getInstance(), ilSearchSettings\getInstance(), getUserId(), and settings().

56  {
57  $this->user_id = $a_user_id;
59 
60  include_once('Services/Search/classes/class.ilUserSearchCache.php');
61  $this->cache = ilUserSearchCache::_getInstance($this->getUserId());
62 
63  $this->offset = $this->settings->getMaxHits() * ($this->cache->getResultPageNumber() - 1);
64  }
settings()
Definition: settings.php:2
static _getInstance($a_usr_id)
Get singleton instance.
+ Here is the call graph for this function:

Member Function Documentation

◆ addFilter()

ilLuceneSearchResultFilter::addFilter ( ilLuceneResultFilter  $filter)

add filter

Parameters

Definition at line 85 of file class.ilLuceneSearchResultFilter.php.

86  {
87  $this->filters[] = $filter;
88  }

◆ append()

ilLuceneSearchResultFilter::append (   $a_ref_id,
  $a_obj_id 
)
protected

Append to filtered results.

Parameters
intref_id
intobj_id

Definition at line 276 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

277  {
278  $this->checked[$a_ref_id] = $a_obj_id;
279  }
+ Here is the caller graph for this function:

◆ checkFilter()

ilLuceneSearchResultFilter::checkFilter (   $a_ref_id)
protected

check appended filter

Parameters
int$a_ref_idreference id
Returns
bool

Definition at line 261 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

262  {
263  foreach ($this->filters as $filter) {
264  if (!$filter->filter($a_ref_id)) {
265  return false;
266  }
267  }
268  return true;
269  }
+ Here is the caller graph for this function:

◆ filter()

ilLuceneSearchResultFilter::filter ( )

Filter search results.

Do RBAC checks.

public

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

Definition at line 195 of file class.ilLuceneSearchResultFilter.php.

References $DIC, $tree, ilObject\_getAllReferences(), append(), checkFilter(), getCandidates(), ilLoggerFactory\getLogger(), getRequiredPermission(), getResultIds(), isOffsetReached(), and settings().

196  {
197  global $DIC;
198 
199  $ilAccess = $DIC['ilAccess'];
200  $tree = $DIC['tree'];
201 
202  // get ref_ids and check access
203  $counter = 0;
204  $offset_counter = 0;
205 
206  foreach ($this->getCandidates() as $obj_id) {
207  // Check referenced objects
208  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
209  // Check filter
210  if (!$this->checkFilter($ref_id)) {
211  $this->cache->appendToFailed($ref_id);
212  continue;
213  }
214 
215  // Access failed by prior check
216  if ($this->cache->isFailed($ref_id)) {
217  continue;
218  }
219  // Offset check
220  if ($this->cache->isChecked($ref_id) and !$this->isOffsetReached($offset_counter)) {
221  ilLoggerFactory::getLogger('src')->debug('Result was checked');
222  $offset_counter++;
223  break;
224  }
225 
226  // RBAC check
227  if ($ilAccess->checkAccessOfUser(
228  $this->getUserId(),
229  $this->getRequiredPermission(),
230  '',
231  $ref_id,
232  '',
233  $obj_id
234  )) {
235  ++$counter;
236  $offset_counter++;
237  $this->append($ref_id, $obj_id);
238  $this->cache->appendToChecked($ref_id, $obj_id);
239  break;
240  } else {
241  $this->cache->appendToFailed($ref_id);
242  }
243  }
244  if ($counter >= $this->settings->getMaxHits()) {
245  $this->limit_reached = true;
246  $this->cache->setResults($this->getResultIds());
247  $this->cache->save();
248  return false;
249  }
250  }
251  $this->cache->setResults($this->getResultIds());
252  $this->cache->save();
253  return true;
254  }
settings()
Definition: settings.php:2
checkFilter($a_ref_id)
check appended filter
global $DIC
Definition: saml.php:7
static _getAllReferences($a_id)
get all reference ids of object
isOffsetReached($a_current_nr)
Check if offset is reached.
getRequiredPermission()
Get required permission.
append($a_ref_id, $a_obj_id)
Append to filtered results.
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

◆ getCandidates()

ilLuceneSearchResultFilter::getCandidates ( )

get result ids

Returns
array result ids

Definition at line 104 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

105  {
106  return $this->result ? $this->result : array();
107  }
+ Here is the caller graph for this function:

◆ getInstance()

static ilLuceneSearchResultFilter::getInstance (   $a_user_id)
static
Parameters
int$a_user_iduser_id
Returns

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

Referenced by ilLuceneAdvancedSearchGUI\performSearch(), ilLuceneSearchGUI\performSearch(), ilSoapObjectAdministration\searchObjects(), ilLuceneAdvancedSearchGUI\showSavedResults(), and ilLuceneSearchGUI\showSavedResults().

73  {
74  if (self::$instance == null) {
75  return self::$instance = new ilLuceneSearchResultFilter($a_user_id);
76  }
77  return self::$instance;
78  }
Validate Lucene search results Do access checks, create ref_ids from obj_ids...
+ Here is the caller graph for this function:

◆ getMaxHits()

ilLuceneSearchResultFilter::getMaxHits ( )

get max hits

Returns
int max hits per page

Definition at line 170 of file class.ilLuceneSearchResultFilter.php.

References settings().

171  {
172  return $this->settings->getMaxHits();
173  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ getRequiredPermission()

ilLuceneSearchResultFilter::getRequiredPermission ( )

Get required permission.

Returns
string required rbac permission

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

References $required_permission.

Referenced by filter().

+ Here is the caller graph for this function:

◆ getResultIds()

ilLuceneSearchResultFilter::getResultIds ( )

get filtered ids

Returns
array array of filtered ref_ids

Definition at line 140 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

141  {
142  return $this->checked ? $this->checked : array();
143  }
+ Here is the caller graph for this function:

◆ getResultObjIds()

ilLuceneSearchResultFilter::getResultObjIds ( )

get filtered ids

Returns
array array of filtered ref_ids

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

150  {
151  foreach ($this->checked as $obj_id) {
152  $obj_ids[] = $obj_id;
153  }
154  return $obj_ids ? $obj_ids : array();
155  }

◆ getResults()

ilLuceneSearchResultFilter::getResults ( )

get results

Returns
array array of ref_ids

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

162  {
163  return $this->checked ? $this->checked : array();
164  }

◆ getUserId()

ilLuceneSearchResultFilter::getUserId ( )

Get user id.

Returns
int user_id

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

References $user_id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ isLimitReached()

ilLuceneSearchResultFilter::isLimitReached ( )

Check if search max hits is reached.

Returns
bool max hits reached

Definition at line 131 of file class.ilLuceneSearchResultFilter.php.

References $limit_reached.

◆ isOffsetReached()

ilLuceneSearchResultFilter::isOffsetReached (   $a_current_nr)
protected

Check if offset is reached.

Parameters
int$a_current_nrCurrent result number
Returns
bool

Definition at line 286 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

287  {
288  return $a_current_nr < $this->offset ? false : true;
289  }
+ Here is the caller graph for this function:

◆ loadFromDb()

ilLuceneSearchResultFilter::loadFromDb ( )

Load results from db.

Returns

Definition at line 179 of file class.ilLuceneSearchResultFilter.php.

180  {
181  $this->checked = $this->cache->getResults();
182  }

◆ setCandidates()

ilLuceneSearchResultFilter::setCandidates (   $a_ids)

Set result ids.

Parameters
mixed$a_idsLucene result ids or instance of Iterator
Returns
void

Definition at line 95 of file class.ilLuceneSearchResultFilter.php.

96  {
97  $this->result = $a_ids;
98  }

Field Documentation

◆ $cache

ilLuceneSearchResultFilter::$cache
protected

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

◆ $checked

ilLuceneSearchResultFilter::$checked = array()
protected

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

◆ $filters

ilLuceneSearchResultFilter::$filters = array()
protected

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

◆ $instance

ilLuceneSearchResultFilter::$instance = null
staticprotected

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

◆ $limit_reached

ilLuceneSearchResultFilter::$limit_reached = false
protected

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

Referenced by isLimitReached().

◆ $offset

ilLuceneSearchResultFilter::$offset = 0
protected

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

◆ $required_permission

ilLuceneSearchResultFilter::$required_permission = 'visible'
protected

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

Referenced by getRequiredPermission().

◆ $result

ilLuceneSearchResultFilter::$result = array()
protected

Definition at line 39 of file class.ilLuceneSearchResultFilter.php.

◆ $settings

ilLuceneSearchResultFilter::$settings
protected

Definition at line 41 of file class.ilLuceneSearchResultFilter.php.

◆ $user_id

ilLuceneSearchResultFilter::$user_id = null
protected

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

Referenced by getUserId().


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