ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLuceneSearchGUI.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.ilSearchSettings.php';
25include_once './Services/Search/classes/class.ilSearchBaseGUI.php';
26include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchFields.php';
27include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
28include_once './Services/Administration/interfaces/interface.ilAdministrationCommandHandling.php';
29
45{
46 protected $ilTabs;
47
51 public function __construct()
52 {
53 global $ilTabs;
54
55 $this->tabs_gui = $ilTabs;
56 parent::__construct();
58 $this->initUserSearchCache();
59 }
60
64 public function executeCommand()
65 {
66 global $ilBench, $ilCtrl;
67
68 $ilBench->start('Lucene', '0900_executeCommand');
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71
72 $this->prepareOutput();
73 switch ($next_class) {
74 case "ilpropertyformgui":
75 /*$this->initStandardSearchForm(ilSearchBaseGUI::SEARCH_FORM_LUCENE);
76 $ilCtrl->setReturn($this, 'storeRoot');
77 $ilCtrl->forwardCommand($this->form);*/
78 $form = $this->getSearchAreaForm();
79 $ilCtrl->setReturn($this, 'storeRoot');
80 $ilCtrl->forwardCommand($form);
81 break;
82
83 case 'ilobjectcopygui':
84 $this->ctrl->setReturn($this, '');
85 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
86 $cp = new ilObjectCopyGUI($this);
87 $this->ctrl->forwardCommand($cp);
88 break;
89
90 default:
92 if (!$cmd) {
93 $cmd = "showSavedResults";
94 }
95 $this->handleCommand($cmd);
96 break;
97 }
98 $ilBench->stop('Lucene', '0900_executeCommand');
99 return true;
100 }
101
105 public function prepareOutput()
106 {
107 parent::prepareOutput();
108 $this->getTabs();
109 return true;
110 }
111
117 protected function getType()
118 {
119 if (count($this->search_cache)) {
121 }
123 }
124
130 protected function getDetails()
131 {
132 return (array) $this->search_cache->getItemFilter();
133 }
134
140 protected function getMimeDetails()
141 {
142 return (array) $this->search_cache->getMimeFilter();
143 }
144
148 protected function remoteSearch()
149 {
150 $query = trim(ilUtil::stripSlashes($_POST['queryString']));
151
152 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
153 $qp = new ilLuceneQueryParser($query);
154 $qp->parseAutoWildcard();
155
156 $query = $qp->getQuery();
157
158 $this->search_cache->setRoot((int) $_POST['root_id']);
159 $this->search_cache->setQuery(ilUtil::stripSlashes($query));
160 $this->search_cache->save();
161
162 $this->search();
163 }
164
169 protected function showSavedResults()
170 {
171 global $ilUser,$ilBench;
172
173 if (!strlen($this->search_cache->getQuery())) {
174 $this->showSearchForm();
175 return false;
176 }
177
178 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
179 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
180 $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
181 $qp->parse();
182 $searcher = ilLuceneSearcher::getInstance($qp);
183 $searcher->search();
184
185 // Load saved results
186 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
188 $filter->loadFromDb();
189
190 // Highlight
191 $searcher->highlight($filter->getResultObjIds());
192
193 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
194 $presentation = new ilSearchResultPresentation($this);
195 $presentation->setResults($filter->getResultIds());
196
197 $presentation->setSearcher($searcher);
198
199 // TODO: other handling required
200 $this->addPager($filter, 'max_page');
201
202 $presentation->setPreviousNext($this->prev_link, $this->next_link);
203
204 $this->showSearchForm();
205
206 if ($presentation->render()) {
207 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
208 } elseif (strlen($this->search_cache->getQuery())) {
209 ilUtil::sendInfo(sprintf($this->lng->txt('search_no_match_hint'), $qp->getQuery()));
210 }
211 }
212
217 protected function search()
218 {
219 if (!$this->form->checkInput()) {
220 $this->search_cache->deleteCachedEntries();
221 // Reset details
222 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
224 $this->showSearchForm();
225 return false;
226 }
227
228 unset($_SESSION['max_page']);
229 $this->search_cache->deleteCachedEntries();
230
231 // Reset details
232 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
234
235 $this->performSearch();
236 }
237
241 protected function performSearch()
242 {
243 global $ilUser,$ilBench;
244
245 unset($_SESSION['vis_references']);
246
247 $filter_query = '';
248 if ($this->search_cache->getItemFilter() and ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
249 $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions();
250 foreach ((array) $this->search_cache->getItemFilter() as $obj => $value) {
251 if (!$filter_query) {
252 $filter_query .= '+( ';
253 } else {
254 $filter_query .= 'OR';
255 }
256 $filter_query .= (' ' . (string) $filter_settings[$obj]['filter'] . ' ');
257 }
258 $filter_query .= ') ';
259 }
260 // begin-patch mime_filter
261 $mime_query = '';
262 if ($this->search_cache->getMimeFilter() and ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
263 $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions();
264 foreach ($this->search_cache->getMimeFilter() as $mime => $value) {
265 if (!$mime_query) {
266 $mime_query .= '+( ';
267 } else {
268 $mime_query .= 'OR';
269 }
270 $mime_query .= (' ' . (string) $filter_settings[$mime]['filter'] . ' ');
271 }
272 $mime_query .= ') ';
273 }
274
275 // begin-patch creation_date
276 $cdate_query = $this->parseCreationFilter();
277
278
279
280 $filter_query = $filter_query . ' ' . $mime_query . ' ' . $cdate_query;
281
282 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
283 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
284
285 $query = $this->search_cache->getQuery();
286 if ($query) {
287 $query = ' +(' . $query . ')';
288 }
289 $qp = new ilLuceneQueryParser($filter_query . $query);
290 $qp->parse();
291 $searcher = ilLuceneSearcher::getInstance($qp);
292 $searcher->search();
293
294 // Filter results
295 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
296 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
298 $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
299 $filter->setCandidates($searcher->getResult());
300 $filter->filter();
301
302 if ($filter->getResultObjIds()) {
303 $searcher->highlight($filter->getResultObjIds());
304 }
305
306 // Show results
307 $this->showSearchForm();
308
309 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
310 $presentation = new ilSearchResultPresentation($this);
311 $presentation->setResults($filter->getResultIds());
312 $presentation->setSearcher($searcher);
313
314 // TODO: other handling required
315 $ilBench->start('Lucene', '1500_fo');
316 $this->addPager($filter, 'max_page');
317 $ilBench->stop('Lucene', '1500_fo');
318
319 $presentation->setPreviousNext($this->prev_link, $this->next_link);
320
321 if ($presentation->render()) {
322 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
323 } else {
324 ilUtil::sendInfo(sprintf($this->lng->txt('search_no_match_hint'), $this->search_cache->getQuery()));
325 }
326 }
327
331 protected function storeRoot()
332 {
333 $form = $this->getSearchAreaForm();
334
335 $this->root_node = $form->getItemByPostVar('area')->getValue();
336 $this->search_cache->setRoot($this->root_node);
337 $this->search_cache->save();
338 $this->search_cache->deleteCachedEntries();
339
340 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
342
343 $this->performSearch();
344 }
345
349 protected function getTabs()
350 {
351 global $ilHelp;
352
353 $ilHelp->setScreenIdComponent("src_luc");
354
355 $this->tabs_gui->addTarget('search', $this->ctrl->getLinkTarget($this));
356
357 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
358 $this->tabs_gui->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
359 }
360
361 if ($this->fields->getActiveFields() && !ilSearchSettings::getInstance()->getHideAdvancedSearch()) {
362 $this->tabs_gui->addTarget('search_advanced', $this->ctrl->getLinkTargetByClass('illuceneAdvancedSearchgui'));
363 }
364
365 $this->tabs_gui->setTabActive('search');
366 }
367
374 protected function initUserSearchCache()
375 {
376 global $ilUser;
377
378 include_once('Services/Search/classes/class.ilUserSearchCache.php');
379 $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
380 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_DEFAULT);
381 if ((int) $_GET['page_number']) {
382 $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
383 }
384 if (isset($_POST['term'])) {
385 $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['term']));
386 if ($_POST['item_filter_enabled']) {
387 $filtered = array();
388 foreach (ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data) {
389 if ($_POST['filter_type'][$type]) {
390 $filtered[$type] = 1;
391 }
392 }
393 $this->search_cache->setItemFilter($filtered);
394
395 // Mime filter
396 $mime = array();
397 foreach (ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data) {
398 if ($_POST['filter_type'][$type]) {
399 $mime[$type] = 1;
400 }
401 }
402 $this->search_cache->setMimeFilter($mime);
403 }
404 $this->search_cache->setCreationFilter($this->loadCreationFilter());
405 if (!$_POST['item_filter_enabled']) {
406 // @todo: keep item filter settings
407 $this->search_cache->setItemFilter(array());
408 $this->search_cache->setMimeFilter(array());
409 }
410 if (!$_POST['screation']) {
411 $this->search_cache->setCreationFilter(array());
412 }
413 }
414 }
415
421 protected function fillAdminPanel()
422 {
423 global $lng;
424
425 $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
426
427 // admin panel commands
428 if ((count($this->admin_panel_commands) > 0)) {
429 foreach ($this->admin_panel_commands as $cmd) {
430 $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
431 $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
432 $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
433 $this->tpl->parseCurrentBlock();
434 }
435
436 $adm_cmds = true;
437 }
438 if ($adm_cmds) {
439 $this->tpl->setCurrentBlock("lucene_adm_view_components");
440 $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
441 $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
442 $this->tpl->parseCurrentBlock();
443 $adm_view_cmp = true;
444 }
445
446 // admin view button
447 if (is_array($this->admin_view_button)) {
448 if (is_array($this->admin_view_button)) {
449 $this->tpl->setCurrentBlock("lucene_admin_button");
450 $this->tpl->setVariable(
451 "LUCENE_ADMIN_MODE_LINK",
452 $this->admin_view_button["link"]
453 );
454 $this->tpl->setVariable(
455 "LUCENE_TXT_ADMIN_MODE",
456 $this->admin_view_button["txt"]
457 );
458 $this->tpl->parseCurrentBlock();
459 }
460 $this->tpl->setCurrentBlock("lucene_admin_view");
461 $this->tpl->parseCurrentBlock();
462 $adm_view = true;
463 }
464
465 // creation selector
466 if (is_array($this->creation_selector)) {
467 $this->tpl->setCurrentBlock("lucene_add_commands");
468 if ($adm_cmds) {
469 $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
470 }
471 $this->tpl->setVariable(
472 "LUCENE_SELECT_OBJTYPE_REPOS",
473 $this->creation_selector["options"]
474 );
475 $this->tpl->setVariable(
476 "LUCENE_BTN_NAME_REPOS",
477 $this->creation_selector["command"]
478 );
479 $this->tpl->setVariable(
480 "LUCENE_TXT_ADD_REPOS",
481 $this->creation_selector["txt"]
482 );
483 $this->tpl->parseCurrentBlock();
484 $creation_selector = true;
485 }
486 if ($adm_view || $creation_selector) {
487 $this->tpl->setCurrentBlock("lucene_adm_panel");
488 if ($adm_view_cmp) {
489 $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
490 }
491 $this->tpl->parseCurrentBlock();
492 }
493 }
494
498 protected function addAdminPanelCommand($a_cmd, $a_txt)
499 {
500 $this->admin_panel_commands[] =
501 array("cmd" => $a_cmd, "txt" => $a_txt);
502 }
503
507 protected function setAdminViewButton($a_link, $a_txt)
508 {
509 $this->admin_view_button =
510 array("link" => $a_link, "txt" => $a_txt);
511 }
512
513 protected function setPageFormAction($a_action)
514 {
515 $this->page_form_action = $a_action;
516 }
517
522 protected function showSearchForm()
523 {
524 global $ilCtrl, $lng;
525
526 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_search.html', 'Services/Search');
527
528 // include js needed
529 include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
531 $this->tpl->addJavascript("./Services/Search/js/Search.js");
532
533 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
534
535 $this->tpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this, 'performSearch'));
536 $this->tpl->setVariable("TERM", ilUtil::prepareFormOutput($this->search_cache->getQuery()));
537 include_once("./Services/UIComponent/Button/classes/class.ilSubmitButton.php");
539 $btn->setCommand("performSearch");
540 $btn->setCaption("search");
541 $this->tpl->setVariable("SUBMIT_BTN", $btn->render());
542 $this->tpl->setVariable("TXT_OPTIONS", $lng->txt("options"));
543 $this->tpl->setVariable("ARR_IMG", ilGlyphGUI::get(ilGlyphGUI::CARET));
544 $this->tpl->setVariable("TXT_COMBINATION", $lng->txt("search_term_combination"));
545 $this->tpl->setVariable('TXT_COMBINATION_DEFAULT', ilSearchSettings::getInstance()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND ? $lng->txt('search_all_words') : $lng->txt('search_any_word'));
546 $this->tpl->setVariable("TXT_AREA", $lng->txt("search_area"));
547
548 if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
549 $this->tpl->setCurrentBlock("type_sel");
550 $this->tpl->setVariable('TXT_TYPE_DEFAULT', $lng->txt("search_off"));
551 $this->tpl->setVariable("ARR_IMGT", ilGlyphGUI::get(ilGlyphGUI::CARET));
552 $this->tpl->setVariable("TXT_FILTER_BY_TYPE", $lng->txt("search_filter_by_type"));
553 $this->tpl->setVariable('FORM', $this->form->getHTML());
554 $this->tpl->parseCurrentBlock();
555 }
556
557 // search area form
558 $this->tpl->setVariable('SEARCH_AREA_FORM', $this->getSearchAreaForm()->getHTML());
559 $this->tpl->setVariable("TXT_CHANGE", $lng->txt("change"));
560
561 if (ilSearchSettings::getInstance()->isDateFilterEnabled()) {
562 // begin-patch creation_date
563 $this->tpl->setVariable('TXT_FILTER_BY_CDATE', $this->lng->txt('search_filter_cd'));
564 $this->tpl->setVariable('TXT_CD_OFF', $this->lng->txt('search_off'));
565 $this->tpl->setVariable('FORM_CD', $this->getCreationDateForm()->getHTML());
566 $this->tpl->setVariable("ARR_IMG_CD", ilGlyphGUI::get(ilGlyphGUI::CARET));
567 // end-patch creation_date
568 }
569
570
571 return true;
572 }
573
574
579 protected function parseCreationFilter()
580 {
581 $options = $this->search_cache->getCreationFilter();
582
583 if (!$options['enabled']) {
584 return '';
585 }
586 $limit = new ilDate($options['date'], IL_CAL_UNIX);
587
588 switch ($options['ontype']) {
589 case 1:
590 // after
591 $limit->increment(IL_CAL_DAY, 1);
592 $now = new ilDate(time(), IL_CAL_UNIX);
593 return '+(cdate:[' . $limit->get(IL_CAL_DATE) . ' TO ' . $now->get(IL_CAL_DATE) . '*]) ';
594
595 case 2:
596 // before
597 return '+(cdate:[* TO ' . $limit->get(IL_CAL_DATE) . ']) ';
598
599 case 3:
600 // on
601 return '+(cdate:' . $limit->get(IL_CAL_DATE) . '*) ';
602
603 }
604 return '';
605 }
606 // end-patch creation_date
607}
sprintf('%.4f', $callTime)
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DAY
Class for single dates.
static get($a_glyph, $a_text="")
Get glyph html.
static getInstance()
Get singleton instance.
@classDescription GUI for simple Lucene search
remoteSearch()
Search from main menu.
parseCreationFilter()
Parse creation date.
getType()
Get type of search (details | fast)
showSavedResults()
Show saved results.
showSearchForm()
Show search form.
setAdminViewButton($a_link, $a_txt)
Show admin view button.
fillAdminPanel()
Put admin panel into template:
initUserSearchCache()
Init user search cache.
storeRoot()
Store new root node.
getMimeDetails()
Needed for base class search form.
getDetails()
Needed for base class search form.
executeCommand()
Execute Command.
performSearch()
Perform search.
search()
Search (button pressed)
prepareOutput()
Add admin panel command.
addAdminPanelCommand($a_cmd, $a_txt)
Add a command to the admin panel.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
GUI class for the workflow of copying objects.
static initJavascript()
Init javascript.
initStandardSearchForm($a_mode)
Init standard search form.
addPager($result, $a_session_key)
Add Pager.
getSearchAreaForm()
Init standard search form.
loadCreationFilter()
Load creation date filter.
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()
Factory.
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)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $ilBench
Definition: ilias.php:18
global $ilCtrl
Definition: ilias.php:18
$query
$type
if(isset($_POST['submit'])) $form
$errors fields
Definition: imgupload.php:51
$ilUser
Definition: imgupload.php:18