ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLuceneSearcher.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResult.php';
25
36{
37 const TYPE_STANDARD = 1;
38 const TYPE_USER = 2;
39
40 private static $instance = null;
41
42 private $query_parser = null;
43 private $result = null;
44 private $highlighter = null;
45 private $page_number = 1;
47
53 private function __construct($qp)
54 {
55 $this->result = new ilLuceneSearchResult();
56 $this->result->setCallback(array($this,'nextResultPage'));
57 $this->query_parser = $qp;
58 }
59
67 public static function getInstance(ilLuceneQueryParser $qp)
68 {
69 if (self::$instance) {
70 return self::$instance;
71 }
72 return self::$instance = new ilLuceneSearcher($qp);
73 }
74
79 public function setType($a_type)
80 {
81 $this->type = $a_type;
82 }
83
88 public function getType()
89 {
90 return $this->type;
91 }
92
93
98 public function search()
99 {
100 $this->performSearch();
101 }
102
108 public function highlight($a_obj_ids)
109 {
110 global $ilBench,$ilSetting;
111
112 include_once './Services/Search/classes/Lucene/class.ilLuceneHighlighterResultParser.php';
113
114 // TODO error handling
115 if (!$this->query_parser->getQuery()) {
116 return;
117 }
118
119 // Search in combined index
120 $ilBench->start('Lucene', 'SearchHighlight');
121 try {
122 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
123 $res = ilRpcClientFactory::factory('RPCSearchHandler')->highlight(
124 CLIENT_ID . '_' . $ilSetting->get('inst_id', 0),
125 $a_obj_ids,
126 $this->query_parser->getQuery()
127 );
128 } catch (Exception $e) {
129 ilLoggerFactory::getLogger('src')->error('Highlighting failed with message: ' . $e->getMessage());
131 }
132
133 include_once './Services/Search/classes/Lucene/class.ilLuceneHighlighterResultParser.php';
134 $this->highlighter = new ilLuceneHighlighterResultParser();
135 $this->highlighter->setResultString($res);
136 $this->highlighter->parse();
137
138 return $this->highlighter;
139 }
140
146 public function nextResultPage()
147 {
148 $this->page_number++;
149 $this->performSearch();
150 }
151
156 public function getHighlighter()
157 {
158 return $this->highlighter;
159 }
160
166 public function getResult()
167 {
168 if ($this->result instanceof ilLuceneSearchResult) {
169 return $this->result;
170 }
171 // TODO Error handling
172 }
173
179 public function getPageNumber()
180 {
181 return $this->page_number;
182 }
183
188 protected function performSearch()
189 {
190 global $ilBench,$ilSetting;
191
192 // TODO error handling
193 if (!$this->query_parser->getQuery()) {
194 return;
195 }
196 $ilBench->start('Lucene', 'SearchCombinedIndex');
197 try {
198 switch ($this->getType()) {
199
200 case self::TYPE_USER:
201 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
202 $res = ilRpcClientFactory::factory('RPCSearchHandler')->searchUsers(
203 CLIENT_ID . '_' . $ilSetting->get('inst_id', 0),
204 (string) $this->query_parser->getQuery()
205 );
206 break;
207
209 default:
210 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
211 $res = ilRpcClientFactory::factory('RPCSearchHandler')->search(
212 CLIENT_ID . '_' . $ilSetting->get('inst_id', 0),
213 (string) $this->query_parser->getQuery(),
214 $this->getPageNumber()
215 );
216 break;
217
218 }
219 ilLoggerFactory::getLogger('src')->debug('Searching for: ' . $this->query_parser->getQuery());
220 } catch (Exception $e) {
221 ilLoggerFactory::getLogger('src')->error('Searching failed with message: ' . $e->getMessage());
222 return;
223 }
224
225 // Parse results
226 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultParser.php';
228 $parser->parse($this->result);
229 return;
230 }
231}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
static getLogger($a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
Search result implementing iterator interface.
Reads and parses lucene search results.
performSearch()
search lucene
highlight($a_obj_ids)
Highlight/Detail query.
__construct($qp)
Constructor.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
getPageNumber()
get current page number
nextResultPage()
get next result page
setType($a_type)
Set search type.
getHighlighter()
get highlighter
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
global $ilBench
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res
$a_type
Definition: workflow.php:92