ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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/Administration/interfaces/interface.ilAdministrationCommandHandling.php';
28
44{
45 protected $ilTabs;
46
50 public function __construct()
51 {
52 global $DIC;
53
54 $ilTabs = $DIC['ilTabs'];
55
56 $this->tabs_gui = $ilTabs;
59 $this->initUserSearchCache();
60 }
61
65 public function executeCommand()
66 {
67 global $DIC;
68
69 $ilBench = $DIC['ilBench'];
70 $ilCtrl = $DIC['ilCtrl'];
71
72 $ilBench->start('Lucene', '0900_executeCommand');
73 $next_class = $this->ctrl->getNextClass($this);
74 $cmd = $this->ctrl->getCmd();
75
76 $this->prepareOutput();
77 switch ($next_class) {
78 case "ilpropertyformgui":
79 /*$this->initStandardSearchForm(ilSearchBaseGUI::SEARCH_FORM_LUCENE);
80 $ilCtrl->setReturn($this, 'storeRoot');
81 $ilCtrl->forwardCommand($this->form);*/
82 $form = $this->getSearchAreaForm();
83 $ilCtrl->setReturn($this, 'storeRoot');
84 $ilCtrl->forwardCommand($form);
85 break;
86
87 case 'ilobjectcopygui':
88 $this->ctrl->setReturn($this, '');
89 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
90 $cp = new ilObjectCopyGUI($this);
91 $this->ctrl->forwardCommand($cp);
92 break;
93
94 default:
96 if (!$cmd) {
97 $cmd = "showSavedResults";
98 }
99 $this->handleCommand($cmd);
100 break;
101 }
102 $ilBench->stop('Lucene', '0900_executeCommand');
103 return true;
104 }
105
109 public function prepareOutput()
110 {
111 parent::prepareOutput();
112 $this->getTabs();
113 return true;
114 }
115
121 protected function getType()
122 {
123 if (count($this->search_cache)) {
125 }
127 }
128
134 protected function getDetails()
135 {
136 return (array) $this->search_cache->getItemFilter();
137 }
138
144 protected function getMimeDetails()
145 {
146 return (array) $this->search_cache->getMimeFilter();
147 }
148
152 protected function remoteSearch()
153 {
154 $query = trim(ilUtil::stripSlashes($_POST['queryString']));
155
156 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
157 $qp = new ilLuceneQueryParser($query);
158 $qp->parseAutoWildcard();
159
160 $query = $qp->getQuery();
161
162 $this->search_cache->setRoot((int) $_POST['root_id']);
163 $this->search_cache->setQuery(ilUtil::stripSlashes($query));
164 $this->search_cache->save();
165
166 $this->search();
167 }
168
173 protected function showSavedResults()
174 {
175 global $DIC;
176
177 $ilUser = $DIC['ilUser'];
178 $ilBench = $DIC['ilBench'];
179
180 if (!strlen($this->search_cache->getQuery())) {
181 $this->showSearchForm();
182 return false;
183 }
184
185 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
186 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
187 $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
188 $qp->parse();
189 $searcher = ilLuceneSearcher::getInstance($qp);
190 $searcher->search();
191
192 // Load saved results
193 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
195 $filter->loadFromDb();
196
197 // Highlight
198 $searcher->highlight($filter->getResultObjIds());
199
200 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
201 $presentation = new ilSearchResultPresentation($this);
202 $presentation->setResults($filter->getResultIds());
203
204 $presentation->setSearcher($searcher);
205
206 // TODO: other handling required
207 $this->addPager($filter, 'max_page');
208
209 $presentation->setPreviousNext($this->prev_link, $this->next_link);
210
211 $this->showSearchForm();
212
213 if ($presentation->render()) {
214 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
215 } elseif (strlen($this->search_cache->getQuery())) {
216 ilUtil::sendInfo(sprintf($this->lng->txt('search_no_match_hint'), $qp->getQuery()));
217 }
218 }
219
224 protected function search()
225 {
226 if (!$this->form->checkInput()) {
227 $this->search_cache->deleteCachedEntries();
228 // Reset details
229 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
231 $this->showSearchForm();
232 return false;
233 }
234
235 unset($_SESSION['max_page']);
236 $this->search_cache->deleteCachedEntries();
237
238 // Reset details
239 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
241
242 $this->performSearch();
243 }
244
248 protected function performSearch()
249 {
250 global $DIC;
251
252 $ilUser = $DIC['ilUser'];
253 $ilBench = $DIC['ilBench'];
254
255 unset($_SESSION['vis_references']);
256
257 $filter_query = '';
258 if ($this->search_cache->getItemFilter() and ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
259 $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions();
260 foreach ((array) $this->search_cache->getItemFilter() as $obj => $value) {
261 if (!$filter_query) {
262 $filter_query .= '+( ';
263 } else {
264 $filter_query .= 'OR';
265 }
266 $filter_query .= (' ' . (string) $filter_settings[$obj]['filter'] . ' ');
267 }
268 $filter_query .= ') ';
269 }
270 // begin-patch mime_filter
271 $mime_query = '';
272 if ($this->search_cache->getMimeFilter() and ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
273 $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions();
274 foreach ($this->search_cache->getMimeFilter() as $mime => $value) {
275 if (!$mime_query) {
276 $mime_query .= '+( ';
277 } else {
278 $mime_query .= 'OR';
279 }
280 $mime_query .= (' ' . (string) $filter_settings[$mime]['filter'] . ' ');
281 }
282 $mime_query .= ') ';
283 }
284
285 // begin-patch creation_date
286 $cdate_query = $this->parseCreationFilter();
287
288
289
290 $filter_query = $filter_query . ' ' . $mime_query . ' ' . $cdate_query;
291
292 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
293 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
294
295 $query = $this->search_cache->getQuery();
296 if ($query) {
297 $query = ' +(' . $query . ')';
298 }
299 $qp = new ilLuceneQueryParser($filter_query . $query);
300 $qp->parse();
301 $searcher = ilLuceneSearcher::getInstance($qp);
302 $searcher->search();
303
304 // Filter results
305 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
306 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
308 $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
309 $filter->setCandidates($searcher->getResult());
310 $filter->filter();
311
312 if ($filter->getResultObjIds()) {
313 $searcher->highlight($filter->getResultObjIds());
314 }
315
316 // Show results
317 $this->showSearchForm();
318
319 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
320 $presentation = new ilSearchResultPresentation($this);
321 $presentation->setResults($filter->getResultIds());
322 $presentation->setSearcher($searcher);
323
324 // TODO: other handling required
325 $ilBench->start('Lucene', '1500_fo');
326 $this->addPager($filter, 'max_page');
327 $ilBench->stop('Lucene', '1500_fo');
328
329 $presentation->setPreviousNext($this->prev_link, $this->next_link);
330
331 if ($presentation->render()) {
332 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
333 } else {
334 ilUtil::sendInfo(sprintf($this->lng->txt('search_no_match_hint'), $this->search_cache->getQuery()));
335 }
336 }
337
341 protected function storeRoot()
342 {
343 $form = $this->getSearchAreaForm();
344
345 $this->root_node = $form->getItemByPostVar('area')->getValue();
346 $this->search_cache->setRoot($this->root_node);
347 $this->search_cache->save();
348 $this->search_cache->deleteCachedEntries();
349
350 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
352
353 $this->performSearch();
354 }
355
359 protected function getTabs()
360 {
361 global $DIC;
362
363 $ilHelp = $DIC['ilHelp'];
364
365 $ilHelp->setScreenIdComponent("src_luc");
366
367 $this->tabs_gui->addTarget('search', $this->ctrl->getLinkTarget($this));
368
369 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
370 $this->tabs_gui->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
371 }
372
373 if ($this->fields->getActiveFields() && !ilSearchSettings::getInstance()->getHideAdvancedSearch()) {
374 $this->tabs_gui->addTarget('search_advanced', $this->ctrl->getLinkTargetByClass('illuceneAdvancedSearchgui'));
375 }
376
377 $this->tabs_gui->setTabActive('search');
378 }
379
386 protected function initUserSearchCache()
387 {
388 global $DIC;
389
390 $ilUser = $DIC['ilUser'];
391
392 include_once('Services/Search/classes/class.ilUserSearchCache.php');
393 $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
394 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_DEFAULT);
395 if ((int) $_GET['page_number']) {
396 $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
397 }
398 if (isset($_POST['term'])) {
399 $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['term']));
400 if ($_POST['item_filter_enabled']) {
401 $filtered = array();
402 foreach (ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data) {
403 if ($_POST['filter_type'][$type]) {
404 $filtered[$type] = 1;
405 }
406 }
407 $this->search_cache->setItemFilter($filtered);
408
409 // Mime filter
410 $mime = array();
411 foreach (ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data) {
412 if ($_POST['filter_type'][$type]) {
413 $mime[$type] = 1;
414 }
415 }
416 $this->search_cache->setMimeFilter($mime);
417 }
418 $this->search_cache->setCreationFilter($this->loadCreationFilter());
419 if (!$_POST['item_filter_enabled']) {
420 // @todo: keep item filter settings
421 $this->search_cache->setItemFilter(array());
422 $this->search_cache->setMimeFilter(array());
423 }
424 if (!$_POST['screation']) {
425 $this->search_cache->setCreationFilter(array());
426 }
427 }
428 }
429
435 protected function fillAdminPanel()
436 {
437 global $DIC;
438
439 $lng = $DIC['lng'];
440
441 $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
442
443 // admin panel commands
444 if ((count((array) $this->admin_panel_commands) > 0)) {
445 foreach ($this->admin_panel_commands as $cmd) {
446 $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
447 $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
448 $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
449 $this->tpl->parseCurrentBlock();
450 }
451
452 $adm_cmds = true;
453 }
454 if ($adm_cmds) {
455 $this->tpl->setCurrentBlock("lucene_adm_view_components");
456 $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
457 $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
458 $this->tpl->parseCurrentBlock();
459 $adm_view_cmp = true;
460 }
461
462 // admin view button
463 if (is_array($this->admin_view_button)) {
464 if (is_array($this->admin_view_button)) {
465 $this->tpl->setCurrentBlock("lucene_admin_button");
466 $this->tpl->setVariable(
467 "LUCENE_ADMIN_MODE_LINK",
468 $this->admin_view_button["link"]
469 );
470 $this->tpl->setVariable(
471 "LUCENE_TXT_ADMIN_MODE",
472 $this->admin_view_button["txt"]
473 );
474 $this->tpl->parseCurrentBlock();
475 }
476 $this->tpl->setCurrentBlock("lucene_admin_view");
477 $this->tpl->parseCurrentBlock();
478 $adm_view = true;
479 }
480
481 // creation selector
482 if (is_array($this->creation_selector)) {
483 $this->tpl->setCurrentBlock("lucene_add_commands");
484 if ($adm_cmds) {
485 $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
486 }
487 $this->tpl->setVariable(
488 "LUCENE_SELECT_OBJTYPE_REPOS",
489 $this->creation_selector["options"]
490 );
491 $this->tpl->setVariable(
492 "LUCENE_BTN_NAME_REPOS",
493 $this->creation_selector["command"]
494 );
495 $this->tpl->setVariable(
496 "LUCENE_TXT_ADD_REPOS",
497 $this->creation_selector["txt"]
498 );
499 $this->tpl->parseCurrentBlock();
500 $creation_selector = true;
501 }
502 if ($adm_view || $creation_selector) {
503 $this->tpl->setCurrentBlock("lucene_adm_panel");
504 if ($adm_view_cmp) {
505 $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
506 }
507 $this->tpl->parseCurrentBlock();
508 }
509 }
510
514 protected function addAdminPanelCommand($a_cmd, $a_txt)
515 {
516 $this->admin_panel_commands[] =
517 array("cmd" => $a_cmd, "txt" => $a_txt);
518 }
519
523 protected function setAdminViewButton($a_link, $a_txt)
524 {
525 $this->admin_view_button =
526 array("link" => $a_link, "txt" => $a_txt);
527 }
528
529 protected function setPageFormAction($a_action)
530 {
531 $this->page_form_action = $a_action;
532 }
533
538 protected function showSearchForm()
539 {
540 global $DIC;
541
542 $ilCtrl = $DIC['ilCtrl'];
543 $lng = $DIC['lng'];
544
545 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_search.html', 'Services/Search');
546
547 // include js needed
548 include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
550 $this->tpl->addJavascript("./Services/Search/js/Search.js");
551
552 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
553
554 $this->tpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this, 'performSearch'));
555 $this->tpl->setVariable("TERM", ilUtil::prepareFormOutput($this->search_cache->getQuery()));
556 $this->tpl->setVariable("SEARCH_LABEL", $lng->txt("search"));
557 include_once("./Services/UIComponent/Button/classes/class.ilSubmitButton.php");
559 $btn->setCommand("performSearch");
560 $btn->setCaption("search");
561 $this->tpl->setVariable("SUBMIT_BTN", $btn->render());
562 $this->tpl->setVariable("TXT_OPTIONS", $lng->txt("options"));
563 $this->tpl->setVariable("ARR_IMG", ilGlyphGUI::get(ilGlyphGUI::CARET));
564 $this->tpl->setVariable("TXT_COMBINATION", $lng->txt("search_term_combination"));
565 $this->tpl->setVariable('TXT_COMBINATION_DEFAULT', ilSearchSettings::getInstance()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND ? $lng->txt('search_all_words') : $lng->txt('search_any_word'));
566 $this->tpl->setVariable("TXT_AREA", $lng->txt("search_area"));
567
568 if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
569 $this->tpl->setCurrentBlock("type_sel");
570 $this->tpl->setVariable('TXT_TYPE_DEFAULT', $lng->txt("search_off"));
571 $this->tpl->setVariable("ARR_IMGT", ilGlyphGUI::get(ilGlyphGUI::CARET));
572 $this->tpl->setVariable("TXT_FILTER_BY_TYPE", $lng->txt("search_filter_by_type"));
573 $this->tpl->setVariable('FORM', $this->form->getHTML());
574 $this->tpl->parseCurrentBlock();
575 }
576
577 // search area form
578 $this->tpl->setVariable('SEARCH_AREA_FORM', $this->getSearchAreaForm()->getHTML());
579 $this->tpl->setVariable("TXT_CHANGE", $lng->txt("change"));
580
581 if (ilSearchSettings::getInstance()->isDateFilterEnabled()) {
582 // begin-patch creation_date
583 $this->tpl->setVariable('TXT_FILTER_BY_CDATE', $this->lng->txt('search_filter_cd'));
584 $this->tpl->setVariable('TXT_CD_OFF', $this->lng->txt('search_off'));
585 $this->tpl->setVariable('TXT_CD_ON', $this->lng->txt('search_on'));
586 $this->tpl->setVariable('FORM_CD', $this->getCreationDateForm()->getHTML());
587 $this->tpl->setVariable("ARR_IMG_CD", ilGlyphGUI::get(ilGlyphGUI::CARET));
588 // end-patch creation_date
589 }
590
591
592 return true;
593 }
594
595
600 protected function parseCreationFilter()
601 {
602 $options = $this->search_cache->getCreationFilter();
603
604 if (!$options['enabled']) {
605 return '';
606 }
607 $limit = new ilDate($options['date'], IL_CAL_UNIX);
608
609 switch ($options['ontype']) {
610 case 1:
611 // after
612 $limit->increment(IL_CAL_DAY, 1);
613 $now = new ilDate(time(), IL_CAL_UNIX);
614 return '+(cdate:[' . $limit->get(IL_CAL_DATE) . ' TO ' . $now->get(IL_CAL_DATE) . '*]) ';
615
616 case 2:
617 // before
618 return '+(cdate:[* TO ' . $limit->get(IL_CAL_DATE) . ']) ';
619
620 case 3:
621 // on
622 return '+(cdate:' . $limit->get(IL_CAL_DATE) . '*) ';
623
624 }
625 return '';
626 }
627 // end-patch creation_date
628}
$_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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
$type
$data
Definition: storeScorm.php:23
$errors fields
Definition: imgupload.php:51
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46