ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 86 of file class.ilLuceneSearchResultFilter.php.

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

◆ append()

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

Append to filtered results.

Parameters
intref_id
intobj_id

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

Referenced by filter().

285  {
286  $this->checked[$a_ref_id] = $a_obj_id;
287  }
+ 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 267 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

268  {
269  foreach($this->filters as $filter)
270  {
271  if(!$filter->filter($a_ref_id))
272  {
273  return false;
274  }
275  }
276  return true;
277  }
+ 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 197 of file class.ilLuceneSearchResultFilter.php.

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

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

References array.

Referenced by filter().

106  {
107  return $this->result ? $this->result : array();
108  }
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  {
76  return self::$instance = new ilLuceneSearchResultFilter($a_user_id);
77  }
78  return self::$instance;
79  }
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 172 of file class.ilLuceneSearchResultFilter.php.

References settings().

173  {
174  return $this->settings->getMaxHits();
175  }
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 123 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 141 of file class.ilLuceneSearchResultFilter.php.

References array.

Referenced by filter().

142  {
143  return $this->checked ? $this->checked : array();
144  }
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 150 of file class.ilLuceneSearchResultFilter.php.

References array.

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

◆ getResults()

ilLuceneSearchResultFilter::getResults ( )

get results

Returns
array array of ref_ids

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

References array.

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

◆ getUserId()

ilLuceneSearchResultFilter::getUserId ( )

Get user id.

Returns
int user_id

Definition at line 114 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 132 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 294 of file class.ilLuceneSearchResultFilter.php.

Referenced by filter().

295  {
296  return $a_current_nr < $this->offset ? false : true;
297  }
+ Here is the caller graph for this function:

◆ loadFromDb()

ilLuceneSearchResultFilter::loadFromDb ( )

Load results from db.

Returns

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

182  {
183  $this->checked = $this->cache->getResults();
184  }

◆ setCandidates()

ilLuceneSearchResultFilter::setCandidates (   $a_ids)

Set result ids.

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

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

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

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: