ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLuceneHighlighterResultParser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
32 private string $result_string = '';
33 private array $result = [];
34 private float $max_score = 0;
35
36
37
38 public function getMaxScore(): float
39 {
40 return $this->max_score;
41 }
42
43 public function setMaxScore(float $a_score): void
44 {
45 $this->max_score = $a_score;
46 }
47
48 public function getRelevance(int $a_obj_id, int $sub_id): float
49 {
50 if (!$this->getMaxScore()) {
51 return 0;
52 }
53
54 $score = $this->result[$a_obj_id][$sub_id]['score'];
55 return $score / $this->getMaxScore() * 100;
56 }
57
58 public function setResultString(string $a_res): void
59 {
60 $this->result_string = $a_res;
61 }
62
63 public function getResultString(): string
64 {
66 }
67
72 public function parse(): bool
73 {
74 if (!strlen($this->getResultString())) {
75 return false;
76 }
77 ilLoggerFactory::getLogger('src')->debug($this->getResultString());
78 $root = new SimpleXMLElement($this->getResultString());
79 $this->setMaxScore((float) $root['maxScore']);
80 foreach ($root->children() as $object) {
81 $obj_id = (string) $object['id'];
82 foreach ($object->children() as $item) {
83 $sub_id = (string) $item['id'];
84
85 // begin-patch mime_filter
86 $score = (string) $item['absoluteScore'];
87 $this->result[$obj_id][$sub_id]['score'] = $score;
88 // end-patch mime_filter
89
90 foreach ($item->children() as $field) {
91 $name = (string) $field['name'];
92 $this->result[$obj_id][$sub_id][$name] = (string) $field;
93 }
94 }
95 }
96 return true;
97 }
98
99 public function getTitle(int $a_obj_id, int $a_sub_id): string
100 {
101 return $this->result[$a_obj_id][$a_sub_id]['title'] ?? '';
102 }
103
104 public function getDescription(int $a_obj_id, int $a_sub_id): string
105 {
106 return $this->result[$a_obj_id][$a_sub_id]['description'] ?? '';
107 }
108
109 public function getContent(int $a_obj_id, int $a_sub_id): string
110 {
111 return $this->result[$a_obj_id][$a_sub_id]['content'] ?? '';
112 }
113
117 public function getSubItemIds(int $a_obj_id): array
118 {
119 $sub_item_ids = array();
120 if (!isset($this->result[$a_obj_id])) {
121 return array();
122 }
123 foreach ($this->result[$a_obj_id] as $sub_item_id => $data) {
124 if ($sub_item_id) {
125 $sub_item_ids[] = $sub_item_id;
126 }
127 }
128 return $sub_item_ids;
129 }
130}
static getLogger(string $a_component_id)
Get component logger.
Parses result XML from lucene search highlight.