ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
84 return true;
85 }
86 // if the number of candidates is smaller than the total number of hits
87 // get next result page
88 if(count($this->objects) < $this->getTotalHits())
89 {
90 ilLoggerFactory::getLogger('src')->debug("Trying to get next result page...");
91 @call_user_func($this->listener);
92 }
93 // Check again
94 if($this->position < count($this->objects))
95 {
96 return true;
97 }
98 return false;
99 }
100
105 public function key()
106 {
107 return $this->position;
108 }
109
114 public function current()
115 {
116 return $this->objects[$this->position];
117 }
118
123 public function next()
124 {
125 $this->position++;
126 }
127
128
129
135 public function getCandidates()
136 {
137 return $this->objects ? $this->objects : array();
138 }
139
147 public function addObject($a_value,$a_relevance = 0)
148 {
149 $this->objects[] = $a_value;
150 $this->relevance[$a_value] = $a_relevance;
151 }
152
158 public function getRelevance($a_obj_id)
159 {
160 if(!$this->getMaxScore())
161 {
162 return 0;
163 }
164 return isset($this->relevance[$a_obj_id]) ? $this->relevance[$a_obj_id] / $this->getMaxScore() * 100 : 0;
165 }
166
167
173 public function setLimit($a_limit)
174 {
175 $this->limit = $a_limit;
176 }
177
183 public function getLimit()
184 {
185 return $this->limit;
186 }
187
188
194 public function setMaxScore($a_score)
195 {
196 $this->max_score = $a_score;
197 }
198
204 public function getMaxScore()
205 {
206 return $this->max_score;
207 }
208
213 public function setTotalHits($a_hits)
214 {
215 $this->total_hits = $a_hits;
216 }
217
223 public function getTotalHits()
224 {
225 return $this->total_hits;
226 }
227}
228?>
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.