ILIAS  release_8 Revision v8.24
class.ilLuceneSearchResult.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27class ilLuceneSearchResult implements Iterator
28{
32 private array $listener = [];
33 private int $position = 0;
34
35 private int $limit = 0;
36 private int $total_hits = 0;
37 private float $max_score = 0;
38
39 private array $objects = [];
40 private array $relevance = [];
41
42
43
48 public function setCallback(array $a_callback): void
49 {
50 $this->listener = $a_callback;
51 }
52
56 public function rewind()
57 {
58 $this->position = 0;
59 }
60
66 public function valid()
67 {
68 if ($this->position < count($this->objects)) {
69 return true;
70 }
71 // if the number of candidates is smaller than the total number of hits
72 // get next result page
73 if (count($this->objects) < $this->getTotalHits()) {
74 ilLoggerFactory::getLogger('src')->debug("Trying to get next result page...");
75 @call_user_func($this->listener);
76 }
77 // Check again
78 if ($this->position < count($this->objects)) {
79 return true;
80 }
81 return false;
82 }
83
88 public function key()
89 {
90 return $this->position;
91 }
92
97 public function current()
98 {
99 return $this->objects[$this->position];
100 }
101
105 public function next()
106 {
107 $this->position++;
108 }
109
110
111
112 public function getCandidates(): array
113 {
114 return $this->objects;
115 }
116
117 public function addObject(int $a_value, float $a_relevance = 0): void
118 {
119 $this->objects[] = $a_value;
120 $this->relevance[$a_value] = $a_relevance;
121 }
122
123 public function getRelevance(int $a_obj_id): float
124 {
125 if (!$this->getMaxScore()) {
126 return 0;
127 }
128 return isset($this->relevance[$a_obj_id]) ? $this->relevance[$a_obj_id] / $this->getMaxScore() * 100 : 0;
129 }
130
131
132 public function setLimit(int $a_limit): void
133 {
134 $this->limit = $a_limit;
135 }
136
137 public function getLimit(): int
138 {
139 return $this->limit;
140 }
141
142
143 public function setMaxScore(float $a_score): void
144 {
145 $this->max_score = $a_score;
146 }
147
148 public function getMaxScore(): float
149 {
150 return $this->max_score;
151 }
152
153 public function setTotalHits(int $a_hits): void
154 {
155 $this->total_hits = $a_hits;
156 }
157
158 public function getTotalHits(): int
159 {
160 return $this->total_hits;
161 }
162}
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCallback(array $a_callback)
set search callback
addObject(int $a_value, float $a_relevance=0)