ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 {
73 case 'ilobjectcopygui':
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 {
83 $cmd = "showSavedResults";
84 }
85 $this->handleCommand($cmd);
86 break;
87 }
88 return true;
89 }
90
91
96 public function showSavedResults()
97 {
98 global $ilUser,$ilBench;
99
100 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
101 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
102 $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
103 $qp->parse();
104 $searcher = ilLuceneSearcher::getInstance($qp);
105 $searcher->search();
106
107 // Load saved results
108 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
110 $filter->loadFromDb();
111
112 // Highlight
113 if($filter->getResultObjIds()) {
114 $searcher->highlight($filter->getResultObjIds());
115 }
116
117 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lucene_adv_search.html','Services/Search');
118 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
119 $presentation = new ilSearchResultPresentation($this);
120 $presentation->setResults($filter->getResultIds());
121 $presentation->setSearcher($searcher);
122
123
124 // TODO: other handling required
125 $this->addPager($filter,'max_page');
126 $presentation->setPreviousNext($this->prev_link, $this->next_link);
127
128 if($presentation->render())
129 {
130 $this->tpl->setVariable('SEARCH_RESULTS',$presentation->getHTML(true));
131 }
132 elseif(strlen(trim($qp->getQuery())))
133 {
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 {
143 $this->fillAdminPanel();
144 }
145 }
146
150 protected function initFormSearch()
151 {
152 global $tree;
153
154 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
155
156 $this->form = new ilPropertyFormGUI();
157 $this->form->setFormAction($this->ctrl->getFormAction($this,'search'));
158 $this->form->setTitle($this->lng->txt('search_advanced'));
159 $this->form->addCommandButton('search',$this->lng->txt('search'));
160 $this->form->addCommandButton('reset',$this->lng->txt('reset'));
161
162 foreach($this->fields->getActiveSections() as $definition)
163 {
164 if($definition['name'] != 'default')
165 {
167 $section->setTitle($definition['name']);
168 $this->form->addItem($section);
169 }
170
171 foreach($definition['fields'] as $field_name)
172 {
173 if(is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(),$field_name,$this->form)))
174 {
175 $this->form->addItem($element);
176 }
177 }
178 }
179 return true;
180 }
181
185 protected function remoteSearch()
186 {
187 $this->search_cache->setRoot((int) $_POST['root_id']);
188 $this->search_cache->setQuery(array('lom_content' => ilUtil::stripSlashes($_POST['queryString'])));
189 $this->search_cache->save();
190 $this->search();
191 }
192
193 protected function search()
194 {
195 if(!is_array($this->search_cache->getQuery()))
196 {
197 // TOD: handle empty advances search
198 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
199 $this->showSavedResults();
200 return false;
201 }
202 unset($_SESSION['max_page']);
203 $this->search_cache->deleteCachedEntries();
204
205 // Reset details
206 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
208
209 $this->performSearch();
210 }
211
215 protected function reset()
216 {
217 $this->search_cache->setQuery(array());
218 $this->search_cache->save();
219 $this->showSavedResults();
220 }
221
225 protected function performSearch()
226 {
227 global $ilUser,$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 {
237 ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
238 $this->showSavedResults();
239 return false;
240 }
241
242 $searcher = ilLuceneSearcher::getInstance($qp);
243 $searcher->search();
244
245 // Filter results
246 $ilBench->start('Lucene','ResultFilter');
247 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
248 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
250 $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
251 $filter->setCandidates($searcher->getResult());
252 $filter->filter();
253 $ilBench->stop('Lucene','ResultFilter');
254
255 if($filter->getResultObjIds()) {
256 $searcher->highlight($filter->getResultObjIds());
257 }
258
259 // Show results
260 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lucene_adv_search.html','Services/Search');
261 include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
262 $presentation = new ilSearchResultPresentation($this);
263 $presentation->setResults($filter->getResultIds());
264 $presentation->setSearcher($searcher);
265
266 // TODO: other handling required
267 $ilBench->start('Lucene','1500_fo');
268 $this->addPager($filter,'max_page');
269 $ilBench->stop('Lucene','1500_fo');
270 $presentation->setPreviousNext($this->prev_link, $this->next_link);
271
272 if($presentation->render())
273 {
274 $this->tpl->setVariable('SEARCH_RESULTS',$presentation->getHTML(true));
275 }
276 else
277 {
278 ilUtil::sendInfo($this->lng->txt('search_no_match'));
279 }
280
281 // and finally add search form
282 $this->initFormSearch();
283 $this->tpl->setVariable('SEARCH_TABLE',$this->form->getHTML());
284
285 if($filter->getResultIds())
286 {
287 $this->fillAdminPanel();
288 }
289 }
290
294 public function prepareOutput()
295 {
296 parent::prepareOutput();
297 $this->getTabs();
298 return true;
299 }
300
304 protected function getTabs()
305 {
306 global $ilHelp;
307
308 $ilHelp->setScreenIdComponent("src_luc");
309
310 $this->tabs_gui->addTarget('search',$this->ctrl->getLinkTargetByClass('illucenesearchgui'));
311
312 if(ilSearchSettings::getInstance()->isLuceneUserSearchEnabled())
313 {
314 $this->tabs_gui->addTarget('search_user',$this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
315 }
316
317 if(
318 !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
319 $this->fields->getActiveFields())
320 {
321 $this->tabs_gui->addTarget('search_advanced',$this->ctrl->getLinkTarget($this));
322 }
323
324 $this->tabs_gui->setTabActive('search_advanced');
325 }
326
333 protected function initUserSearchCache()
334 {
335 global $ilUser;
336
337 include_once('Services/Search/classes/class.ilUserSearchCache.php');
338 $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
339 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_ADVANCED);
340 if((int) $_GET['page_number'])
341 {
342 $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
343 }
344 if(isset($_POST['query']))
345 {
346 $this->search_cache->setQuery($_POST['query']);
347 }
348 }
349 protected function fillAdminPanel()
350 {
351 global $lng;
352
353 $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
354
355 // admin panel commands
356 if ((count($this->admin_panel_commands) > 0))
357 {
358 foreach($this->admin_panel_commands as $cmd)
359 {
360 $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
361 $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
362 $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
363 $this->tpl->parseCurrentBlock();
364 }
365
366 $adm_cmds = true;
367 }
368 if ($adm_cmds)
369 {
370 $this->tpl->setCurrentBlock("lucene_adm_view_components");
371 $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
372 $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
373 $this->tpl->parseCurrentBlock();
374 $adm_view_cmp = true;
375 }
376
377 // admin view button
378 if (is_array($this->admin_view_button))
379 {
380 if (is_array($this->admin_view_button))
381 {
382 $this->tpl->setCurrentBlock("lucene_admin_button");
383 $this->tpl->setVariable("LUCENE_ADMIN_MODE_LINK",
384 $this->admin_view_button["link"]);
385 $this->tpl->setVariable("LUCENE_TXT_ADMIN_MODE",
386 $this->admin_view_button["txt"]);
387 $this->tpl->parseCurrentBlock();
388 }
389 $this->tpl->setCurrentBlock("lucene_admin_view");
390 $this->tpl->parseCurrentBlock();
391 $adm_view = true;
392 }
393
394 // creation selector
395 if (is_array($this->creation_selector))
396 {
397 $this->tpl->setCurrentBlock("lucene_add_commands");
398 if ($adm_cmds)
399 {
400 $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
401 }
402 $this->tpl->setVariable("LUCENE_SELECT_OBJTYPE_REPOS",
403 $this->creation_selector["options"]);
404 $this->tpl->setVariable("LUCENE_BTN_NAME_REPOS",
405 $this->creation_selector["command"]);
406 $this->tpl->setVariable("LUCENE_TXT_ADD_REPOS",
407 $this->creation_selector["txt"]);
408 $this->tpl->parseCurrentBlock();
409 $creation_selector = true;
410 }
411 if ($adm_view || $creation_selector)
412 {
413 $this->tpl->setCurrentBlock("lucene_adm_panel");
414 if ($adm_view_cmp)
415 {
416 $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
417 }
418 $this->tpl->parseCurrentBlock();
419 }
420 }
421
425 protected function addAdminPanelCommand($a_cmd, $a_txt)
426 {
427 $this->admin_panel_commands[] =
428 array("cmd" => $a_cmd, "txt" => $a_txt);
429 }
430
434 protected function setAdminViewButton($a_link, $a_txt)
435 {
436 $this->admin_view_button =
437 array("link" => $a_link, "txt" => $a_txt);
438 }
439
440 protected function setPageFormAction($a_action)
441 {
442 $this->page_form_action = $a_action;
443 }
444}
445?>
$section
Definition: Utf8Test.php:84
$_GET["client_id"]
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)
$_POST['username']
Definition: cron.php:12
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $ilBench
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$errors fields
Definition: imgupload.php:48
global $ilUser
Definition: imgupload.php:15