ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLuceneSearcher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
29{
30 public const TYPE_STANDARD = 1;
31 public const TYPE_USER = 2;
32
33 private static ?ilLuceneSearcher $instance = null;
34
38 private int $page_number = 1;
40
42
43 private function __construct(ilLuceneQueryParser $qp)
44 {
45 global $DIC;
46
47 $this->setting = $DIC->settings();
48 $this->result = new ilLuceneSearchResult();
49 $this->result->setCallback([$this,'nextResultPage']);
50 $this->query_parser = $qp;
51 }
52
56 public static function getInstance(ilLuceneQueryParser $qp): self
57 {
58 if (self::$instance instanceof ilLuceneSearcher) {
59 return self::$instance;
60 }
61 return self::$instance = new ilLuceneSearcher($qp);
62 }
63
67 public function setType(int $a_type): void
68 {
69 $this->type = $a_type;
70 }
71
75 public function getType(): int
76 {
77 return $this->type;
78 }
79
80
84 public function search(): void
85 {
86 $this->performSearch();
87 }
88
93 public function highlight(array $a_obj_ids): ?ilLuceneHighlighterResultParser
94 {
95 if (!$this->query_parser->getQuery()) {
96 return null;
97 }
98
99 // Search in combined index
100 try {
101 $res = ilRpcClientFactory::factory('RPCSearchHandler')->highlight(
102 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
103 $a_obj_ids,
104 $this->query_parser->getQuery()
105 );
106 } catch (Exception $e) {
107 ilLoggerFactory::getLogger('src')->error('Highlighting failed with message: ' . $e->getMessage());
109 }
110
111 $this->highlighter = new ilLuceneHighlighterResultParser();
112 $this->highlighter->setResultString($res);
113 $this->highlighter->parse();
114
115 return $this->highlighter;
116 }
117
121 public function nextResultPage(): void
122 {
123 $this->page_number++;
124 $this->performSearch();
125 }
126
131 {
132 return $this->highlighter;
133 }
134
139 {
140 return $this->result;
141 }
142
146 public function getPageNumber(): int
147 {
148 return $this->page_number;
149 }
150
154 protected function performSearch(): void
155 {
156 if (!$this->query_parser->getQuery()) {
157 return;
158 }
159 try {
160 switch ($this->getType()) {
161 case self::TYPE_USER:
163 $res = ilRpcClientFactory::factory('RPCSearchHandler')->searchUsers(
164 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
165 $this->query_parser->getQuery()
166 );
167 break;
168
170 default:
171 $res = ilRpcClientFactory::factory('RPCSearchHandler')->search(
172 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
173 $this->query_parser->getQuery(),
174 $this->getPageNumber()
175 );
176 break;
177 }
178 ilLoggerFactory::getLogger('src')->debug('Searching for: ' . $this->query_parser->getQuery());
179 } catch (Exception $e) {
180 ilLoggerFactory::getLogger('src')->error('Searching failed with message: ' . $e->getMessage());
181 return;
182 }
183
184 ilLoggerFactory::getLogger('src')->dump($res);
185
186 // Parse results
187 $parser = new ilLuceneSearchResultParser($res);
188 $parser->parse($this->result);
189 }
190}
static getLogger(string $a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
Search result implementing iterator interface.
Reads and parses lucene search results.
ilLuceneHighlighterResultParser $highlighter
ilLuceneSearchResult $result
performSearch()
search lucene
highlight(array $a_obj_ids)
setType(int $a_type)
Set search type.
__construct(ilLuceneQueryParser $qp)
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
ilLuceneQueryParser $query_parser
getPageNumber()
get current page number
static ilLuceneSearcher $instance
nextResultPage()
get next result page
getHighlighter()
get highlighter
static factory(string $a_package, int $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
ILIAS Setting Class.
const CLIENT_ID
Definition: constants.php:41
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26