ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
54
55 $ilTabs = $DIC['ilTabs'];
56
57 $this->tabs_gui = $ilTabs;
58 parent::__construct();
59
61 $this->initUserSearchCache();
62 }
63
67 public function executeCommand()
68 {
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71
72 $this->prepareOutput();
73 switch ($next_class) {
74 case 'ilobjectcopygui':
75 $this->ctrl->setReturn($this);
76 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
77 $cp = new ilObjectCopyGUI($this, '');
78 $this->ctrl->forwardCommand($cp);
79 break;
80
81
82 default:
83 if (!$cmd) {
84 $cmd = "showSavedResults";
85 }
86 $this->handleCommand($cmd);
87 break;
88 }
89 return true;
90 }
91
92
97 public function showSavedResults()
98 {
99 global $DIC;
100
101 $ilUser = $DIC['ilUser'];
102 $ilBench = $DIC['ilBench'];
103
104 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
105 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
106 $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
107 $qp->parse();
108 $searcher = ilLuceneSearcher::getInstance($qp);
109 $searcher->search();
110
111 // Load saved results
112 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
114 $filter->loadFromDb();
115
116 // Highlight
117 if ($filter->getResultObjIds()) {
118 $searcher->highlight($filter->getResultObjIds());
119 }
120
121 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_adv_search.html', 'Services/Search');
122 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
123 $presentation = new ilSearchResultPresentation($this);
124 $presentation->setResults($filter->getResultIds());
125 $presentation->setSearcher($searcher);
126
127
128 // TODO: other handling required
129 $this->addPager($filter, 'max_page');
130 $presentation->setPreviousNext($this->prev_link, $this->next_link);
131
132 if ($presentation->render()) {
133 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
134 } elseif (strlen(trim($qp->getQuery()))) {
135 ilUtil::sendInfo($this->lng->txt('search_no_match'));
136 }
137
138 // and finally add search form
139 $this->initFormSearch();
140 $this->tpl->setVariable('SEARCH_TABLE', $this->form->getHTML());
141
142 if ($filter->getResultIds()) {
143 $this->fillAdminPanel();
144 }
145 }
146
150 protected function initFormSearch()
151 {
152 global $DIC;
153
154 $tree = $DIC['tree'];
155
156 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
157
158 $this->form = new ilPropertyFormGUI();
159 $this->form->setFormAction($this->ctrl->getFormAction($this, 'search'));
160 $this->form->setTitle($this->lng->txt('search_advanced'));
161 $this->form->addCommandButton('search', $this->lng->txt('search'));
162 $this->form->addCommandButton('reset', $this->lng->txt('reset'));
163
164 foreach ($this->fields->getActiveSections() as $definition) {
165 if ($definition['name'] != 'default') {
167 $section->setTitle($definition['name']);
168 $this->form->addItem($section);
169 }
170
171 foreach ($definition['fields'] as $field_name) {
172 if (is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(), $field_name, $this->form))) {
173 $this->form->addItem($element);
174 }
175 }
176 }
177 return true;
178 }
179
183 protected function remoteSearch()
184 {
185 $this->search_cache->setRoot((int) $_POST['root_id']);
186 $this->search_cache->setQuery(array('lom_content' => ilUtil::stripSlashes($_POST['queryString'])));
187 $this->search_cache->save();
188 $this->search();
189 }
190
191 protected function search()
192 {
193 if (!is_array($this->search_cache->getQuery())) {
194 // TOD: handle empty advances search
195 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
196 $this->showSavedResults();
197 return false;
198 }
199 unset($_SESSION['max_page']);
200 $this->search_cache->deleteCachedEntries();
201
202 // Reset details
203 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
205
206 $this->performSearch();
207 }
208
212 protected function reset()
213 {
214 $this->search_cache->setQuery(array());
215 $this->search_cache->save();
216 $this->showSavedResults();
217 }
218
222 protected function performSearch()
223 {
224 global $DIC;
225
226 $ilUser = $DIC['ilUser'];
227 $ilBench = $DIC['ilBench'];
228
229 unset($_SESSION['vis_references']);
230
231 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
232 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
233 $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
234 $qp->parse();
235 if (!strlen(trim($qp->getQuery()))) {
236 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
237 $this->showSavedResults();
238 return false;
239 }
240
241 $searcher = ilLuceneSearcher::getInstance($qp);
242 $searcher->search();
243
244 // Filter results
245 $ilBench->start('Lucene', 'ResultFilter');
246 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
247 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
249 $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
250 $filter->setCandidates($searcher->getResult());
251 $filter->filter();
252 $ilBench->stop('Lucene', 'ResultFilter');
253
254 if ($filter->getResultObjIds()) {
255 $searcher->highlight($filter->getResultObjIds());
256 }
257
258 // Show results
259 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_adv_search.html', 'Services/Search');
260 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
261 $presentation = new ilSearchResultPresentation($this);
262 $presentation->setResults($filter->getResultIds());
263 $presentation->setSearcher($searcher);
264
265 // TODO: other handling required
266 $ilBench->start('Lucene', '1500_fo');
267 $this->addPager($filter, 'max_page');
268 $ilBench->stop('Lucene', '1500_fo');
269 $presentation->setPreviousNext($this->prev_link, $this->next_link);
270
271 if ($presentation->render()) {
272 $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
273 } else {
274 ilUtil::sendInfo($this->lng->txt('search_no_match'));
275 }
276
277 // and finally add search form
278 $this->initFormSearch();
279 $this->tpl->setVariable('SEARCH_TABLE', $this->form->getHTML());
280
281 if ($filter->getResultIds()) {
282 $this->fillAdminPanel();
283 }
284 }
285
289 public function prepareOutput()
290 {
291 parent::prepareOutput();
292 $this->getTabs();
293 return true;
294 }
295
299 protected function getTabs()
300 {
301 global $DIC;
302
303 $ilHelp = $DIC['ilHelp'];
304
305 $ilHelp->setScreenIdComponent("src_luc");
306
307 $this->tabs_gui->addTarget('search', $this->ctrl->getLinkTargetByClass('illucenesearchgui'));
308
309 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
310 $this->tabs_gui->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
311 }
312
313 if (
314 !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
315 $this->fields->getActiveFields()) {
316 $this->tabs_gui->addTarget('search_advanced', $this->ctrl->getLinkTarget($this));
317 }
318
319 $this->tabs_gui->setTabActive('search_advanced');
320 }
321
328 protected function initUserSearchCache()
329 {
330 global $DIC;
331
332 $ilUser = $DIC['ilUser'];
333
334 include_once('Services/Search/classes/class.ilUserSearchCache.php');
335 $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
336 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_ADVANCED);
337 if ((int) $_GET['page_number']) {
338 $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
339 }
340 if (isset($_POST['query'])) {
341 $this->search_cache->setQuery($_POST['query']);
342 }
343 }
344 protected function fillAdminPanel()
345 {
346 global $DIC;
347
348 $lng = $DIC['lng'];
349
350 $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
351
352 // admin panel commands
353 if ((count((array) $this->admin_panel_commands) > 0)) {
354 foreach ($this->admin_panel_commands as $cmd) {
355 $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
356 $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
357 $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
358 $this->tpl->parseCurrentBlock();
359 }
360
361 $adm_cmds = true;
362 }
363 if ($adm_cmds) {
364 $this->tpl->setCurrentBlock("lucene_adm_view_components");
365 $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
366 $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
367 $this->tpl->parseCurrentBlock();
368 $adm_view_cmp = true;
369 }
370
371 // admin view button
372 if (is_array($this->admin_view_button)) {
373 if (is_array($this->admin_view_button)) {
374 $this->tpl->setCurrentBlock("lucene_admin_button");
375 $this->tpl->setVariable(
376 "LUCENE_ADMIN_MODE_LINK",
377 $this->admin_view_button["link"]
378 );
379 $this->tpl->setVariable(
380 "LUCENE_TXT_ADMIN_MODE",
381 $this->admin_view_button["txt"]
382 );
383 $this->tpl->parseCurrentBlock();
384 }
385 $this->tpl->setCurrentBlock("lucene_admin_view");
386 $this->tpl->parseCurrentBlock();
387 $adm_view = true;
388 }
389
390 // creation selector
391 if (is_array($this->creation_selector)) {
392 $this->tpl->setCurrentBlock("lucene_add_commands");
393 if ($adm_cmds) {
394 $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
395 }
396 $this->tpl->setVariable(
397 "LUCENE_SELECT_OBJTYPE_REPOS",
398 $this->creation_selector["options"]
399 );
400 $this->tpl->setVariable(
401 "LUCENE_BTN_NAME_REPOS",
402 $this->creation_selector["command"]
403 );
404 $this->tpl->setVariable(
405 "LUCENE_TXT_ADD_REPOS",
406 $this->creation_selector["txt"]
407 );
408 $this->tpl->parseCurrentBlock();
409 $creation_selector = true;
410 }
411 if ($adm_view || $creation_selector) {
412 $this->tpl->setCurrentBlock("lucene_adm_panel");
413 if ($adm_view_cmp) {
414 $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
415 }
416 $this->tpl->parseCurrentBlock();
417 }
418 }
419
423 protected function addAdminPanelCommand($a_cmd, $a_txt)
424 {
425 $this->admin_panel_commands[] =
426 array("cmd" => $a_cmd, "txt" => $a_txt);
427 }
428
432 protected function setAdminViewButton($a_link, $a_txt)
433 {
434 $this->admin_view_button =
435 array("link" => $a_link, "txt" => $a_txt);
436 }
437
438 protected function setPageFormAction($a_action)
439 {
440 $this->page_form_action = $a_action;
441 }
442}
$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
global $DIC
Definition: saml.php:7
$errors fields
Definition: imgupload.php:51
$ilUser
Definition: imgupload.php:18