ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $root = new SimpleXMLElement($this->getResultString());
113
114 // begin-patch mime_filter
115 $this->setMaxScore((string) $root['maxScore']);
116 // end-patch mime_filter
117
118
119 foreach($root->children() as $object)
120 {
121 $obj_id = (string) $object['id'];
122 foreach($object->children() as $item)
123 {
124 $sub_id = (string) $item['id'];
125
126 // begin-patch mime_filter
127 $score = (string) $item['absoluteScore'];
128 $this->result[$obj_id][$sub_id]['score'] = $score;
129 // end-patch mime_filter
130
131 foreach($item->children() as $field)
132 {
133 $name = (string) $field['name'];
134 $this->result[$obj_id][$sub_id][$name] = (string) $field;
135 }
136 }
137 }
138
139 return true;
140 }
141
148 public function getTitle($a_obj_id,$a_sub_id)
149 {
150 return isset($this->result[$a_obj_id][$a_sub_id]['title']) ? $this->result[$a_obj_id][$a_sub_id]['title'] : null;
151 }
152
159 public function getDescription($a_obj_id,$a_sub_id)
160 {
161 return isset($this->result[$a_obj_id][$a_sub_id]['description']) ? $this->result[$a_obj_id][$a_sub_id]['description'] : null;
162 }
163
170 public function getContent($a_obj_id,$a_sub_id)
171 {
172 return isset($this->result[$a_obj_id][$a_sub_id]['content']) ? $this->result[$a_obj_id][$a_sub_id]['content'] : null;
173 }
174
180 public function getSubItemIds($a_obj_id)
181 {
182 $sub_item_ids = array();
183 if(!isset($this->result[$a_obj_id]))
184 {
185 return array();
186 }
187 foreach($this->result[$a_obj_id] as $sub_item_id => $data)
188 {
189 if($sub_item_id)
190 {
191 $sub_item_ids[] = $sub_item_id;
192 }
193 }
194 return $sub_item_ids ? $sub_item_ids : array();
195 }
196}
197?>
Parses result XML from lucene search highlight.
getDescription($a_obj_id, $a_sub_id)
get description
$data