ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  }
static _getInstance($a_usr_id)
Get singleton instance.
settings()
Definition: settings.php:2
+ 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 273 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

274  {
275  $this->checked[$a_ref_id] = $a_obj_id;
276  }
+ 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 258 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

259  {
260  foreach ($this->filters as $filter) {
261  if (!$filter->filter($a_ref_id)) {
262  return false;
263  }
264  }
265  return true;
266  }
+ 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 $counter, ilObject\_getAllReferences(), append(), checkFilter(), getCandidates(), ilLoggerFactory\getLogger(), getRequiredPermission(), getResultIds(), isOffsetReached(), and settings().

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

References array.

Referenced by filter().

105  {
106  return $this->result ? $this->result : array();
107  }
Create styles array
The data for the language used.
+ 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.

References array.

Referenced by filter().

141  {
142  return $this->checked ? $this->checked : array();
143  }
Create styles array
The data for the language used.
+ 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.

References array.

150  {
151  foreach ($this->checked as $obj_id) {
152  $obj_ids[] = $obj_id;
153  }
154  return $obj_ids ? $obj_ids : array();
155  }
Create styles array
The data for the language used.

◆ getResults()

ilLuceneSearchResultFilter::getResults ( )

get results

Returns
array array of ref_ids

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

References array.

162  {
163  return $this->checked ? $this->checked : array();
164  }
Create styles array
The data for the language used.

◆ 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 283 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

284  {
285  return $a_current_nr < $this->offset ? false : true;
286  }
+ 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: