ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLuceneAdvancedSearchGUI.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/class.ilSearchBaseGUI.php';
25include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchFields.php';
26include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
27include_once './Services/Administration/interfaces/interface.ilAdministrationCommandHandling.php';
28
43{
44 protected $ilTabs;
45
46 protected $fields = null;
47
51 public function __construct()
52 {
53 global $ilTabs;
54
55 $this->tabs_gui = $ilTabs;
56 parent::__construct();
57
59 $this->initUserSearchCache();
60 }
61
65 public function executeCommand()
66 {
67 $next_class = $this->ctrl->getNextClass($this);
68 $cmd = $this->ctrl->getCmd();
69
70 $this->prepareOutput();
71 switch ($next_class) {
72 case 'ilobjectcopygui':
73 $this->ctrl->setReturn($this);
74 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
75 $cp = new ilObjectCopyGUI($this, '');
76 $this->ctrl->forwardCommand($cp);
77 break;
78
79
80 default:
81 if (!$cmd) {
82 $cmd = "showSavedResults";
83 }
84 $this->handleCommand($cmd);
85 break;
86 }
87 return true;
88 }
89
90
95 public function showSavedResults()
96 {
97 global $ilUser,$ilBench;
98
99 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
100 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
101 $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
102 $qp->parse();
103 $searcher = ilLuceneSearcher::getInstance($qp);
104 $searcher->search();
105
106 // Load saved results
107 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
109 $filter->loadFromDb();
110
111 // Highlight
112 if ($filter->getResultObjIds()) {
113 $searcher->highlight($filter->getResultObjIds());
114 }
115
116 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_adv_search.html', 'Services/Search');
117 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
118 $presentation = new ilSearchResultPresentation($this);
119 $presentation->setResults($filter->getResultIds());
120 $presentation->setSearcher($searcher);
121
122
123 // TODO: other handling required
124 $this->addPager($filter, 'max_page');
125 $presentation->setPreviousNext($this->prev_link, $this->next_link);
126
127 if ($presentation->render()) {
128 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
129 } elseif (strlen(trim($qp->getQuery()))) {
130 ilUtil::sendInfo($this->lng->txt('search_no_match'));
131 }
132
133 // and finally add search form
134 $this->initFormSearch();
135 $this->tpl->setVariable('SEARCH_TABLE', $this->form->getHTML());
136
137 if ($filter->getResultIds()) {
138 $this->fillAdminPanel();
139 }
140 }
141
145 protected function initFormSearch()
146 {
147 global $tree;
148
149 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
150
151 $this->form = new ilPropertyFormGUI();
152 $this->form->setFormAction($this->ctrl->getFormAction($this, 'search'));
153 $this->form->setTitle($this->lng->txt('search_advanced'));
154 $this->form->addCommandButton('search', $this->lng->txt('search'));
155 $this->form->addCommandButton('reset', $this->lng->txt('reset'));
156
157 foreach ($this->fields->getActiveSections() as $definition) {
158 if ($definition['name'] != 'default') {
160 $section->setTitle($definition['name']);
161 $this->form->addItem($section);
162 }
163
164 foreach ($definition['fields'] as $field_name) {
165 if (is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(), $field_name, $this->form))) {
166 $this->form->addItem($element);
167 }
168 }
169 }
170 return true;
171 }
172
176 protected function remoteSearch()
177 {
178 $this->search_cache->setRoot((int) $_POST['root_id']);
179 $this->search_cache->setQuery(array('lom_content' => ilUtil::stripSlashes($_POST['queryString'])));
180 $this->search_cache->save();
181 $this->search();
182 }
183
184 protected function search()
185 {
186 if (!is_array($this->search_cache->getQuery())) {
187 // TOD: handle empty advances search
188 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
189 $this->showSavedResults();
190 return false;
191 }
192 unset($_SESSION['max_page']);
193 $this->search_cache->deleteCachedEntries();
194
195 // Reset details
196 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
198
199 $this->performSearch();
200 }
201
205 protected function reset()
206 {
207 $this->search_cache->setQuery(array());
208 $this->search_cache->save();
209 $this->showSavedResults();
210 }
211
215 protected function performSearch()
216 {
217 global $ilUser,$ilBench;
218
219 unset($_SESSION['vis_references']);
220
221 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
222 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
223 $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
224 $qp->parse();
225 if (!strlen(trim($qp->getQuery()))) {
226 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
227 $this->showSavedResults();
228 return false;
229 }
230
231 $searcher = ilLuceneSearcher::getInstance($qp);
232 $searcher->search();
233
234 // Filter results
235 $ilBench->start('Lucene', 'ResultFilter');
236 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
237 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
239 $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
240 $filter->setCandidates($searcher->getResult());
241 $filter->filter();
242 $ilBench->stop('Lucene', 'ResultFilter');
243
244 if ($filter->getResultObjIds()) {
245 $searcher->highlight($filter->getResultObjIds());
246 }
247
248 // Show results
249 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_adv_search.html', 'Services/Search');
250 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
251 $presentation = new ilSearchResultPresentation($this);
252 $presentation->setResults($filter->getResultIds());
253 $presentation->setSearcher($searcher);
254
255 // TODO: other handling required
256 $ilBench->start('Lucene', '1500_fo');
257 $this->addPager($filter, 'max_page');
258 $ilBench->stop('Lucene', '1500_fo');
259 $presentation->setPreviousNext($this->prev_link, $this->next_link);
260
261 if ($presentation->render()) {
262 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
263 } else {
264 ilUtil::sendInfo($this->lng->txt('search_no_match'));
265 }
266
267 // and finally add search form
268 $this->initFormSearch();
269 $this->tpl->setVariable('SEARCH_TABLE', $this->form->getHTML());
270
271 if ($filter->getResultIds()) {
272 $this->fillAdminPanel();
273 }
274 }
275
279 public function prepareOutput()
280 {
281 parent::prepareOutput();
282 $this->getTabs();
283 return true;
284 }
285
289 protected function getTabs()
290 {
291 global $ilHelp;
292
293 $ilHelp->setScreenIdComponent("src_luc");
294
295 $this->tabs_gui->addTarget('search', $this->ctrl->getLinkTargetByClass('illucenesearchgui'));
296
297 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
298 $this->tabs_gui->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
299 }
300
301 if (
302 !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
303 $this->fields->getActiveFields()) {
304 $this->tabs_gui->addTarget('search_advanced', $this->ctrl->getLinkTarget($this));
305 }
306
307 $this->tabs_gui->setTabActive('search_advanced');
308 }
309
316 protected function initUserSearchCache()
317 {
318 global $ilUser;
319
320 include_once('Services/Search/classes/class.ilUserSearchCache.php');
321 $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
322 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_ADVANCED);
323 if ((int) $_GET['page_number']) {
324 $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
325 }
326 if (isset($_POST['query'])) {
327 $this->search_cache->setQuery($_POST['query']);
328 }
329 }
330 protected function fillAdminPanel()
331 {
332 global $lng;
333
334 $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
335
336 // admin panel commands
337 if ((count($this->admin_panel_commands) > 0)) {
338 foreach ($this->admin_panel_commands as $cmd) {
339 $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
340 $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
341 $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
342 $this->tpl->parseCurrentBlock();
343 }
344
345 $adm_cmds = true;
346 }
347 if ($adm_cmds) {
348 $this->tpl->setCurrentBlock("lucene_adm_view_components");
349 $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
350 $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
351 $this->tpl->parseCurrentBlock();
352 $adm_view_cmp = true;
353 }
354
355 // admin view button
356 if (is_array($this->admin_view_button)) {
357 if (is_array($this->admin_view_button)) {
358 $this->tpl->setCurrentBlock("lucene_admin_button");
359 $this->tpl->setVariable(
360 "LUCENE_ADMIN_MODE_LINK",
361 $this->admin_view_button["link"]
362 );
363 $this->tpl->setVariable(
364 "LUCENE_TXT_ADMIN_MODE",
365 $this->admin_view_button["txt"]
366 );
367 $this->tpl->parseCurrentBlock();
368 }
369 $this->tpl->setCurrentBlock("lucene_admin_view");
370 $this->tpl->parseCurrentBlock();
371 $adm_view = true;
372 }
373
374 // creation selector
375 if (is_array($this->creation_selector)) {
376 $this->tpl->setCurrentBlock("lucene_add_commands");
377 if ($adm_cmds) {
378 $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
379 }
380 $this->tpl->setVariable(
381 "LUCENE_SELECT_OBJTYPE_REPOS",
382 $this->creation_selector["options"]
383 );
384 $this->tpl->setVariable(
385 "LUCENE_BTN_NAME_REPOS",
386 $this->creation_selector["command"]
387 );
388 $this->tpl->setVariable(
389 "LUCENE_TXT_ADD_REPOS",
390 $this->creation_selector["txt"]
391 );
392 $this->tpl->parseCurrentBlock();
393 $creation_selector = true;
394 }
395 if ($adm_view || $creation_selector) {
396 $this->tpl->setCurrentBlock("lucene_adm_panel");
397 if ($adm_view_cmp) {
398 $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
399 }
400 $this->tpl->parseCurrentBlock();
401 }
402 }
403
407 protected function addAdminPanelCommand($a_cmd, $a_txt)
408 {
409 $this->admin_panel_commands[] =
410 array("cmd" => $a_cmd, "txt" => $a_txt);
411 }
412
416 protected function setAdminViewButton($a_link, $a_txt)
417 {
418 $this->admin_view_button =
419 array("link" => $a_link, "txt" => $a_txt);
420 }
421
422 protected function setPageFormAction($a_action)
423 {
424 $this->page_form_action = $a_action;
425 }
426}
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a section header in a property form.
static getInstance()
Get singleton instance.
initUserSearchCache()
Init user search cache.
addAdminPanelCommand($a_cmd, $a_txt)
Add a command to the admin panel.
setAdminViewButton($a_link, $a_txt)
Show admin view button.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
GUI class for the workflow of copying objects.
This class represents a property form user interface.
addPager($result, $a_session_key)
Add Pager.
handleCommand($a_cmd)
Handle command.
Presentation of search results using object list gui.
static resetDetails()
reset details As long as static::resetDetails is not possible this method is final
static _getInstance($a_usr_id)
Get singleton instance.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $ilBench
Definition: ilias.php:18
$errors fields
Definition: imgupload.php:51
$ilUser
Definition: imgupload.php:18