ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilRepositoryObjectDetailSearch.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
6
18{
20
21 protected int $obj_id;
22 protected string $type;
23 protected string $query_string;
24
25
26 public function __construct(int $a_obj_id)
27 {
28 $this->obj_id = $a_obj_id;
29 $this->type = ilObject::_lookupType($this->getObjId());
30
32 }
33
34 public function getSettings(): ilSearchSettings
35 {
36 return $this->settings;
37 }
38
39 public function getObjId(): int
40 {
41 return $this->obj_id;
42 }
43
44 public function getType(): string
45 {
46 return $this->type;
47 }
48
49
50 public function setQueryString(string $a_query): void
51 {
52 $this->query_string = $a_query;
53 }
54
55
56 public function getQueryString(): string
57 {
59 }
60
62 {
63 if ($this->getSettings()->enabledLucene()) {
64 return $this->performLuceneSearch();
65 } else {
66 return $this->performDBSearch();
67 }
68 }
69
74 {
75 try {
76 $qp = new ilLuceneQueryParser($this->getQueryString());
77 $qp->parse();
79 ilLoggerFactory::getLogger('src')->warning('Invalid query: ' . $e->getMessage());
80 throw $e;
81 }
82
83 $searcher = ilLuceneSearcher::getInstance($qp);
84 $searcher->highlight(array($this->getObjId()));
85
86 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
87
88 if ($searcher->getHighlighter() instanceof ilLuceneHighlighterResultParser) {
89 foreach ($searcher->getHighlighter()->getSubItemIds($this->getObjId()) as $sub_id) {
90 $detail_search_result->addResultSet(
91 array(
92 'obj_id' => $this->getObjId(),
93 'item_id' => $sub_id,
94 'relevance' => $searcher->getHighlighter()->getRelevance($this->getObjId(), $sub_id),
95 'content' => $searcher->getHighlighter()->getContent($this->getObjId(), $sub_id)
96 )
97 );
98 }
99 }
100 return $detail_search_result;
101 }
102
103
108 {
109 $query_parser = new ilQueryParser($this->getQueryString());
110
111 $query_parser->setCombination(
112 ($this->getSettings()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND) ?
115 );
116 $query_parser->parse();
117
118 if (!$query_parser->validate()) {
119 throw new Exception($query_parser->getMessage());
120 }
121 $search_result = new ilSearchResult();
122
123 $search = ilObjectSearchFactory::getByTypeSearchInstance($this->getType(), $query_parser);
124
125 switch ($this->getType()) {
126 case 'wiki':
127 $search->setFilter(array('wpg'));
128 break;
129 }
130
131 $search->setIdFilter(array($this->getObjId()));
132
133 $search_result->mergeEntries($search->performSearch());
134
135 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
136
137 foreach ($search_result->getEntries() as $entry) {
138 foreach ((array) $entry['child'] as $child) {
139 $detail_search_result->addResultSet(
140 array(
141 'obj_id' => $entry['obj_id'],
142 'item_id' => $child
143 )
144 );
145 }
146 }
147 return $detail_search_result;
148 }
149}
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static getByTypeSearchInstance(string $a_object_type, ilQueryParser $a_query_parser)
static _lookupType(int $id, bool $reference=false)