ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLuceneSearchResult.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
35{
36 private $listener;
37 private $position = 0;
38
39 private $limit = 0;
40 private $total_hits = 0;
41 private $max_score = 0;
42
43 private $objects = [];
44 private $relevance;
45
46
52 public function __construct()
53 {
54 }
55
61 public function setCallback($a_callback)
62 {
63 $this->listener = $a_callback;
64 }
65
70 public function rewind()
71 {
72 $this->position = 0;
73 }
74
80 public function valid()
81 {
82 if ($this->position < count($this->objects)) {
83 return true;
84 }
85 // if the number of candidates is smaller than the total number of hits
86 // get next result page
87 if (count($this->objects) < $this->getTotalHits()) {
88 ilLoggerFactory::getLogger('src')->debug("Trying to get next result page...");
89 @call_user_func($this->listener);
90 }
91 // Check again
92 if ($this->position < count($this->objects)) {
93 return true;
94 }
95 return false;
96 }
97
102 public function key()
103 {
104 return $this->position;
105 }
106
111 public function current()
112 {
113 return $this->objects[$this->position];
114 }
115
120 public function next()
121 {
122 $this->position++;
123 }
124
125
126
132 public function getCandidates()
133 {
134 return $this->objects;
135 }
136
144 public function addObject($a_value, $a_relevance = 0)
145 {
146 $this->objects[] = $a_value;
147 $this->relevance[$a_value] = $a_relevance;
148 }
149
155 public function getRelevance($a_obj_id)
156 {
157 if (!$this->getMaxScore()) {
158 return 0;
159 }
160 return isset($this->relevance[$a_obj_id]) ? $this->relevance[$a_obj_id] / $this->getMaxScore() * 100 : 0;
161 }
162
163
169 public function setLimit($a_limit)
170 {
171 $this->limit = $a_limit;
172 }
173
179 public function getLimit()
180 {
181 return $this->limit;
182 }
183
184
190 public function setMaxScore($a_score)
191 {
192 $this->max_score = $a_score;
193 }
194
200 public function getMaxScore()
201 {
202 return $this->max_score;
203 }
204
209 public function setTotalHits($a_hits)
210 {
211 $this->total_hits = $a_hits;
212 }
213
219 public function getTotalHits()
220 {
221 return $this->total_hits;
222 }
223}
An exception for terminatinating execution or to throw for unit testing.
static getLogger($a_component_id)
Get component logger.
Search result implementing iterator interface.
setCallback($a_callback)
set search callback
getRelevance($a_obj_id)
get relevance
setTotalHits($a_hits)
set total hits
addObject($a_value, $a_relevance=0)
Add object entry.