ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLuceneHighlighterResultParser.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 $result_string = '';
37 private $result = array();
38
39 // begin-patch mime_filter
40 private $max_score = 0;
41 // end-patch mime_filter
42
43
48 public function __construct()
49 {
50
51 }
52
53 // begin-patch mime_filter
54 public function getMaxScore()
55 {
56 return $this->max_score;
57 }
58
59 public function setMaxScore($a_score)
60 {
61 $this->max_score = $a_score;
62 }
63
69 public function getRelevance($a_obj_id, $sub_id)
70 {
71 if(!$this->getMaxScore())
72 {
73 return 0;
74 }
75
76 $score = $this->result[$a_obj_id][$sub_id]['score'];
77 return $score / $this->getMaxScore() * 100;
78 }
79
80 // end-patch mime_filter
81
87 public function setResultString($a_res)
88 {
89 $this->result_string = $a_res;
90 }
91
97 public function getResultString()
98 {
100 }
101
106 public function parse()
107 {
108 if(!strlen($this->getResultString()))
109 {
110 return false;
111 }
112 ilLoggerFactory::getLogger('src')->debug($this->getResultString());
113 $root = new SimpleXMLElement($this->getResultString());
114
115 // begin-patch mime_filter
116 $this->setMaxScore((string) $root['maxScore']);
117 // end-patch mime_filter
118
119
120 foreach($root->children() as $object)
121 {
122 $obj_id = (string) $object['id'];
123 foreach($object->children() as $item)
124 {
125 $sub_id = (string) $item['id'];
126
127 // begin-patch mime_filter
128 $score = (string) $item['absoluteScore'];
129 $this->result[$obj_id][$sub_id]['score'] = $score;
130 // end-patch mime_filter
131
132 foreach($item->children() as $field)
133 {
134 $name = (string) $field['name'];
135 $this->result[$obj_id][$sub_id][$name] = (string) $field;
136 }
137 }
138 }
139
140 return true;
141 }
142
149 public function getTitle($a_obj_id,$a_sub_id)
150 {
151 return isset($this->result[$a_obj_id][$a_sub_id]['title']) ? $this->result[$a_obj_id][$a_sub_id]['title'] : null;
152 }
153
160 public function getDescription($a_obj_id,$a_sub_id)
161 {
162 return isset($this->result[$a_obj_id][$a_sub_id]['description']) ? $this->result[$a_obj_id][$a_sub_id]['description'] : null;
163 }
164
171 public function getContent($a_obj_id,$a_sub_id)
172 {
173 return isset($this->result[$a_obj_id][$a_sub_id]['content']) ? $this->result[$a_obj_id][$a_sub_id]['content'] : null;
174 }
175
181 public function getSubItemIds($a_obj_id)
182 {
183 $sub_item_ids = array();
184 if(!isset($this->result[$a_obj_id]))
185 {
186 return array();
187 }
188 foreach($this->result[$a_obj_id] as $sub_item_id => $data)
189 {
190 if($sub_item_id)
191 {
192 $sub_item_ids[] = $sub_item_id;
193 }
194 }
195 return $sub_item_ids ? $sub_item_ids : array();
196 }
197}
198?>
An exception for terminatinating execution or to throw for unit testing.
static getLogger($a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
getDescription($a_obj_id, $a_sub_id)
get description