ILIAS  release_7 Revision v7.30-3-g800a261c036
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 // begin-patch mime_filter
53 public function getMaxScore()
54 {
55 return $this->max_score;
56 }
57
58 public function setMaxScore($a_score)
59 {
60 $this->max_score = $a_score;
61 }
62
68 public function getRelevance($a_obj_id, $sub_id)
69 {
70 if (!$this->getMaxScore()) {
71 return 0;
72 }
73
74 $score = $this->result[$a_obj_id][$sub_id]['score'];
75 return $score / $this->getMaxScore() * 100;
76 }
77
78 // end-patch mime_filter
79
85 public function setResultString($a_res)
86 {
87 $this->result_string = $a_res;
88 }
89
95 public function getResultString()
96 {
98 }
99
104 public function parse()
105 {
106 if (!strlen($this->getResultString())) {
107 return false;
108 }
109 ilLoggerFactory::getLogger('src')->debug($this->getResultString());
110 $root = new SimpleXMLElement($this->getResultString());
111
112 // begin-patch mime_filter
113 $this->setMaxScore((string) $root['maxScore']);
114 // end-patch mime_filter
115
116
117 foreach ($root->children() as $object) {
118 $obj_id = (string) $object['id'];
119 foreach ($object->children() as $item) {
120 $sub_id = (string) $item['id'];
121
122 // begin-patch mime_filter
123 $score = (string) $item['absoluteScore'];
124 $this->result[$obj_id][$sub_id]['score'] = $score;
125 // end-patch mime_filter
126
127 foreach ($item->children() as $field) {
128 $name = (string) $field['name'];
129 $this->result[$obj_id][$sub_id][$name] = (string) $field;
130 }
131 }
132 }
133
134 return true;
135 }
136
143 public function getTitle($a_obj_id, $a_sub_id)
144 {
145 return isset($this->result[$a_obj_id][$a_sub_id]['title']) ? $this->result[$a_obj_id][$a_sub_id]['title'] : null;
146 }
147
154 public function getDescription($a_obj_id, $a_sub_id)
155 {
156 return isset($this->result[$a_obj_id][$a_sub_id]['description']) ? $this->result[$a_obj_id][$a_sub_id]['description'] : null;
157 }
158
165 public function getContent($a_obj_id, $a_sub_id)
166 {
167 return isset($this->result[$a_obj_id][$a_sub_id]['content']) ? $this->result[$a_obj_id][$a_sub_id]['content'] : null;
168 }
169
175 public function getSubItemIds($a_obj_id)
176 {
177 $sub_item_ids = array();
178 if (!isset($this->result[$a_obj_id])) {
179 return array();
180 }
181 foreach ($this->result[$a_obj_id] as $sub_item_id => $data) {
182 if ($sub_item_id) {
183 $sub_item_ids[] = $sub_item_id;
184 }
185 }
186 return $sub_item_ids ? $sub_item_ids : array();
187 }
188}
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
if($format !==null) $name
Definition: metadata.php:230
$data
Definition: storeScorm.php:23