ILIAS  release_8 Revision v8.24
class.ilLuceneSearcher.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
26
36{
37 public const TYPE_STANDARD = 1;
38 public const TYPE_USER = 2;
39
40 private static ?ilLuceneSearcher $instance = null;
41
45 private int $page_number = 1;
47
49
50 private function __construct(ilLuceneQueryParser $qp)
51 {
52 global $DIC;
53
54 $this->setting = $DIC->settings();
55 $this->result = new ilLuceneSearchResult();
56 $this->result->setCallback([$this,'nextResultPage']);
57 $this->query_parser = $qp;
58 }
59
63 public static function getInstance(ilLuceneQueryParser $qp): self
64 {
65 if (self::$instance instanceof ilLuceneSearcher) {
66 return self::$instance;
67 }
68 return self::$instance = new ilLuceneSearcher($qp);
69 }
70
74 public function setType(int $a_type): void
75 {
76 $this->type = $a_type;
77 }
78
82 public function getType(): int
83 {
84 return $this->type;
85 }
86
87
91 public function search(): void
92 {
93 $this->performSearch();
94 }
95
100 public function highlight(array $a_obj_ids): ?ilLuceneHighlighterResultParser
101 {
102 if (!$this->query_parser->getQuery()) {
103 return null;
104 }
105
106 // Search in combined index
107 try {
108 $res = ilRpcClientFactory::factory('RPCSearchHandler')->highlight(
109 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
110 $a_obj_ids,
111 $this->query_parser->getQuery()
112 );
113 } catch (Exception $e) {
114 ilLoggerFactory::getLogger('src')->error('Highlighting failed with message: ' . $e->getMessage());
116 }
117
118 $this->highlighter = new ilLuceneHighlighterResultParser();
119 $this->highlighter->setResultString($res);
120 $this->highlighter->parse();
121
122 return $this->highlighter;
123 }
124
128 public function nextResultPage(): void
129 {
130 $this->page_number++;
131 $this->performSearch();
132 }
133
138 {
139 return $this->highlighter;
140 }
141
146 {
147 return $this->result;
148 }
149
153 public function getPageNumber(): int
154 {
155 return $this->page_number;
156 }
157
161 protected function performSearch(): void
162 {
163 if (!$this->query_parser->getQuery()) {
164 return;
165 }
166 try {
167 switch ($this->getType()) {
168
169 case self::TYPE_USER:
171 $res = ilRpcClientFactory::factory('RPCSearchHandler')->searchUsers(
172 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
173 $this->query_parser->getQuery()
174 );
175 break;
176
178 default:
179 $res = ilRpcClientFactory::factory('RPCSearchHandler')->search(
180 CLIENT_ID . '_' . $this->setting->get('inst_id', '0'),
181 $this->query_parser->getQuery(),
182 $this->getPageNumber()
183 );
184 break;
185
186 }
187 ilLoggerFactory::getLogger('src')->debug('Searching for: ' . $this->query_parser->getQuery());
188 } catch (Exception $e) {
189 ilLoggerFactory::getLogger('src')->error('Searching failed with message: ' . $e->getMessage());
190 return;
191 }
192
193 ilLoggerFactory::getLogger('src')->dump($res);
194
195 // Parse results
196 $parser = new ilLuceneSearchResultParser($res);
197 $parser->parse($this->result);
198 }
199}
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69