ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 $score): void
44 {
45 $this->max_score = $score;
46 }
47
48 public function getRelevance(int $obj_id, int $sub_id, string $sub_type): float
49 {
50 if (!$this->getMaxScore()) {
51 return 0;
52 }
53
54 $score = $this->result[$obj_id][$sub_type . '__' . $sub_id]['score'] ?? 0;
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_type = (string) $item['type'];
84 $sub_id = (string) $item['id'];
85
86 $this->result[$obj_id][$sub_type . '__' . $sub_id]['id'] = $sub_id;
87 $this->result[$obj_id][$sub_type . '__' . $sub_id]['type'] = $sub_type;
88
89 // begin-patch mime_filter
90 $score = (string) $item['absoluteScore'];
91 $this->result[$obj_id][$sub_type . '__' . $sub_id]['score'] = $score;
92 // end-patch mime_filter
93
94 foreach ($item->children() as $field) {
95 $name = (string) $field['name'];
96 $this->result[$obj_id][$sub_type . '__' . $sub_id][$name] = (string) $field;
97 }
98 }
99 }
100 return true;
101 }
102
103 public function getTitle(int $obj_id, int $sub_id, string $sub_type): string
104 {
105 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['title'] ?? '';
106 }
107
108 public function getDescription(int $obj_id, int $sub_id, string $sub_type): string
109 {
110 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['description'] ?? '';
111 }
112
113 public function getContent(int $obj_id, int $sub_id, string $sub_type): string
114 {
115 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['content'] ?? '';
116 }
117
121 public function getSubItemIds(int $obj_id): array
122 {
123 $sub_item_ids = [];
124 if (!isset($this->result[$obj_id])) {
125 return [];
126 }
127 foreach ($this->result[$obj_id] as $data) {
128 if ($data['id'] <= 0) {
129 continue;
130 }
131 $sub_item_ids[] = ['id' => (int) $data['id'], 'type' => (string) $data['type']];
132 }
133 return $sub_item_ids;
134 }
135}
static getLogger(string $a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
getTitle(int $obj_id, int $sub_id, string $sub_type)
getDescription(int $obj_id, int $sub_id, string $sub_type)
getContent(int $obj_id, int $sub_id, string $sub_type)
getRelevance(int $obj_id, int $sub_id, string $sub_type)