ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 global $ilLog;
83
84 $ilLog->write(__METHOD__.': Iterator valid called '. count($this->objects).' '. $this->position);
85 if($this->position < count($this->objects))
86 {
87 return true;
88 }
89 // if the number of candidates is smaller than the total number of hits
90 // get next result page
91 if(count($this->objects) < $this->getTotalHits())
92 {
93 $ilLog->write("Trying to get next result page...");
94 @call_user_func($this->listener);
95 }
96 // Check again
97 if($this->position < count($this->objects))
98 {
99 return true;
100 }
101 return false;
102 }
103
108 public function key()
109 {
110 return $this->position;
111 }
112
117 public function current()
118 {
119 return $this->objects[$this->position];
120 }
121
126 public function next()
127 {
128 $this->position++;
129 }
130
131
132
138 public function getCandidates()
139 {
140 return $this->objects ? $this->objects : array();
141 }
142
150 public function addObject($a_value,$a_relevance = 0)
151 {
152 $this->objects[] = $a_value;
153 $this->relevance[$a_value] = $a_relevance;
154 }
155
161 public function getRelevance($a_obj_id)
162 {
163 if(!$this->getMaxScore())
164 {
165 return 0;
166 }
167 return isset($this->relevance[$a_obj_id]) ? $this->relevance[$a_obj_id] / $this->getMaxScore() * 100 : 0;
168 }
169
170
176 public function setLimit($a_limit)
177 {
178 $this->limit = $a_limit;
179 }
180
186 public function getLimit()
187 {
188 return $this->limit;
189 }
190
191
197 public function setMaxScore($a_score)
198 {
199 $this->max_score = $a_score;
200 }
201
207 public function getMaxScore()
208 {
209 return $this->max_score;
210 }
211
216 public function setTotalHits($a_hits)
217 {
218 $this->total_hits = $a_hits;
219 }
220
226 public function getTotalHits()
227 {
228 return $this->total_hits;
229 }
230}
231?>
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.