ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRepositoryObjectDetailSearch.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
31{
33
34 protected int $obj_id;
35 protected string $type;
36 protected string $query_string;
37
38
39 public function __construct(int $a_obj_id)
40 {
41 $this->obj_id = $a_obj_id;
42 $this->type = ilObject::_lookupType($this->getObjId());
43
45 }
46
47 public function getSettings(): ilSearchSettings
48 {
49 return $this->settings;
50 }
51
52 public function getObjId(): int
53 {
54 return $this->obj_id;
55 }
56
57 public function getType(): string
58 {
59 return $this->type;
60 }
61
62
63 public function setQueryString(string $a_query): void
64 {
65 $this->query_string = $a_query;
66 }
67
68
69 public function getQueryString(): string
70 {
72 }
73
75 {
76 if ($this->getSettings()->enabledLucene()) {
77 return $this->performLuceneSearch();
78 } else {
79 return $this->performDBSearch();
80 }
81 }
82
87 {
88 try {
89 $qp = new ilLuceneQueryParser($this->getQueryString());
90 $qp->parse();
92 ilLoggerFactory::getLogger('src')->warning('Invalid query: ' . $e->getMessage());
93 throw $e;
94 }
95
96 $searcher = ilLuceneSearcher::getInstance($qp);
97 $searcher->highlight(array($this->getObjId()));
98
99 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
100
101 if ($searcher->getHighlighter() instanceof ilLuceneHighlighterResultParser) {
102 foreach ($searcher->getHighlighter()->getSubItemIds($this->getObjId()) as $sub_id) {
103 $detail_search_result->addResultSet(
104 array(
105 'obj_id' => $this->getObjId(),
106 'item_id' => $sub_id,
107 'relevance' => $searcher->getHighlighter()->getRelevance($this->getObjId(), $sub_id),
108 'content' => $searcher->getHighlighter()->getContent($this->getObjId(), $sub_id)
109 )
110 );
111 }
112 }
113 return $detail_search_result;
114 }
115
116
121 {
122 $query_parser = new ilQueryParser($this->getQueryString());
123
124 $query_parser->setCombination(
125 ($this->getSettings()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND) ?
128 );
129 $query_parser->parse();
130
131 if (!$query_parser->validate()) {
132 throw new Exception($query_parser->getMessage());
133 }
134 $search_result = new ilSearchResult();
135
136 $search = ilObjectSearchFactory::getByTypeSearchInstance($this->getType(), $query_parser);
137
138 switch ($this->getType()) {
139 case 'wiki':
140 $search->setFilter(array('wpg'));
141 break;
142 }
143
144 $search->setIdFilter(array($this->getObjId()));
145
146 $search_result->mergeEntries($search->performSearch());
147
148 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
149
150 foreach ($search_result->getEntries() as $entry) {
151 foreach ((array) $entry['child'] as $child) {
152 $detail_search_result->addResultSet(
153 array(
154 'obj_id' => $entry['obj_id'],
155 'item_id' => $child
156 )
157 );
158 }
159 }
160 return $detail_search_result;
161 }
162}
static getLogger(string $a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static getByTypeSearchInstance(string $a_object_type, ilQueryParser $a_query_parser)
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...