ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilLuceneHighlighterResultParser Class Reference

Parses result XML from lucene search highlight. More...

+ Collaboration diagram for ilLuceneHighlighterResultParser:

Public Member Functions

 getMaxScore ()
 
 setMaxScore (float $score)
 
 getRelevance (int $obj_id, int $sub_id, string $sub_type)
 
 setResultString (string $a_res)
 
 getResultString ()
 
 parse ()
 parse More...
 
 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)
 
 getSubItemIds (int $obj_id)
 

Private Attributes

string $result_string = ''
 
array $result = []
 
float $max_score = 0
 

Detailed Description

Parses result XML from lucene search highlight.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 30 of file class.ilLuceneHighlighterResultParser.php.

Member Function Documentation

◆ getContent()

ilLuceneHighlighterResultParser::getContent ( int  $obj_id,
int  $sub_id,
string  $sub_type 
)

Definition at line 113 of file class.ilLuceneHighlighterResultParser.php.

113 : string
114 {
115 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['content'] ?? '';
116 }

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getLuceneSearchResultAsPanel().

+ Here is the caller graph for this function:

◆ getDescription()

ilLuceneHighlighterResultParser::getDescription ( int  $obj_id,
int  $sub_id,
string  $sub_type 
)

Definition at line 108 of file class.ilLuceneHighlighterResultParser.php.

108 : string
109 {
110 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['description'] ?? '';
111 }

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getLuceneSearchResultAsPanel().

+ Here is the caller graph for this function:

◆ getMaxScore()

ilLuceneHighlighterResultParser::getMaxScore ( )

Definition at line 38 of file class.ilLuceneHighlighterResultParser.php.

References $max_score.

Referenced by getRelevance().

+ Here is the caller graph for this function:

◆ getRelevance()

ilLuceneHighlighterResultParser::getRelevance ( int  $obj_id,
int  $sub_id,
string  $sub_type 
)

Definition at line 48 of file class.ilLuceneHighlighterResultParser.php.

48 : 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 }

References getMaxScore().

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getLuceneSearchResultAsPanel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResultString()

ilLuceneHighlighterResultParser::getResultString ( )

Definition at line 63 of file class.ilLuceneHighlighterResultParser.php.

References $result_string.

Referenced by parse().

+ Here is the caller graph for this function:

◆ getSubItemIds()

ilLuceneHighlighterResultParser::getSubItemIds ( int  $obj_id)
Returns
list<array{id: int, type: string}>

Definition at line 121 of file class.ilLuceneHighlighterResultParser.php.

121 : 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 }

References $data, and ILIAS\Repository\int().

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getLuceneSearchResultAsPanel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilLuceneHighlighterResultParser::getTitle ( int  $obj_id,
int  $sub_id,
string  $sub_type 
)

Definition at line 103 of file class.ilLuceneHighlighterResultParser.php.

103 : string
104 {
105 return $this->result[$obj_id][$sub_type . '__' . $sub_id]['title'] ?? '';
106 }

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getLuceneSearchResultAsPanel().

+ Here is the caller graph for this function:

◆ parse()

ilLuceneHighlighterResultParser::parse ( )

parse

Returns
bool

Definition at line 72 of file class.ilLuceneHighlighterResultParser.php.

72 : 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 }
static getLogger(string $a_component_id)
Get component logger.

References ilLoggerFactory\getLogger(), getResultString(), and setMaxScore().

+ Here is the call graph for this function:

◆ setMaxScore()

ilLuceneHighlighterResultParser::setMaxScore ( float  $score)

Definition at line 43 of file class.ilLuceneHighlighterResultParser.php.

43 : void
44 {
45 $this->max_score = $score;
46 }

Referenced by parse().

+ Here is the caller graph for this function:

◆ setResultString()

ilLuceneHighlighterResultParser::setResultString ( string  $a_res)

Definition at line 58 of file class.ilLuceneHighlighterResultParser.php.

58 : void
59 {
60 $this->result_string = $a_res;
61 }

Field Documentation

◆ $max_score

float ilLuceneHighlighterResultParser::$max_score = 0
private

Definition at line 34 of file class.ilLuceneHighlighterResultParser.php.

Referenced by getMaxScore().

◆ $result

array ilLuceneHighlighterResultParser::$result = []
private

Definition at line 33 of file class.ilLuceneHighlighterResultParser.php.

◆ $result_string

string ilLuceneHighlighterResultParser::$result_string = ''
private

Definition at line 32 of file class.ilLuceneHighlighterResultParser.php.

Referenced by getResultString().


The documentation for this class was generated from the following file: