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