ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
24 include_once './Services/Search/classes/class.ilSearchBaseGUI.php';
25 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchFields.php';
26 include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
27 include_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  $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  {
84  $cmd = "showSavedResults";
85  }
86  $this->handleCommand($cmd);
87  break;
88  }
89  return true;
90  }
91 
92 
97  public function showSavedResults()
98  {
99  global $ilUser,$ilBench;
100 
101  include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
102  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
103  $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
104  $qp->parse();
105  $searcher = ilLuceneSearcher::getInstance($qp);
106  $searcher->search();
107 
108  // Load saved results
109  include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
110  $filter = ilLuceneSearchResultFilter::getInstance($ilUser->getId());
111  $filter->loadFromDb();
112 
113  // Highlight
114  if($filter->getResultObjIds()) {
115  $searcher->highlight($filter->getResultObjIds());
116  }
117 
118  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lucene_adv_search.html','Services/Search');
119  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
120  $presentation = new ilSearchResultPresentation($this);
121  $presentation->setResults($filter->getResultIds());
122  $presentation->setSearcher($searcher);
123 
124 
125  // TODO: other handling required
126  $this->addPager($filter,'max_page');
127  $presentation->setPreviousNext($this->prev_link, $this->next_link);
128 
129  if($presentation->render())
130  {
131  $this->tpl->setVariable('SEARCH_RESULTS',$presentation->getHTML(true));
132  }
133  elseif(strlen(trim($qp->getQuery())))
134  {
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  {
144  $this->fillAdminPanel();
145  }
146  }
147 
151  protected function initFormSearch()
152  {
153  global $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  {
165  if($definition['name'] != 'default')
166  {
168  $section->setTitle($definition['name']);
169  $this->form->addItem($section);
170  }
171 
172  foreach($definition['fields'] as $field_name)
173  {
174  if(is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(),$field_name,$this->form)))
175  {
176  $this->form->addItem($element);
177  }
178  }
179  }
180  return true;
181  }
182 
186  protected function remoteSearch()
187  {
188  $this->search_cache->setRoot((int) $_POST['root_id']);
189  $this->search_cache->setQuery(array('lom_content' => ilUtil::stripSlashes($_POST['queryString'])));
190  $this->search_cache->save();
191  $this->search();
192  }
193 
194  protected function search()
195  {
196  if(!is_array($this->search_cache->getQuery()))
197  {
198  // TOD: handle empty advances search
199  ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
200  $this->showSavedResults();
201  return false;
202  }
203  unset($_SESSION['max_page']);
204  $this->search_cache->deleteCachedEntries();
205 
206  // Reset details
207  include_once './Services/Object/classes/class.ilSubItemListGUI.php';
209 
210  $this->performSearch();
211  }
212 
216  protected function reset()
217  {
218  $this->search_cache->setQuery(array());
219  $this->search_cache->save();
220  $this->showSavedResults();
221  }
222 
226  protected function performSearch()
227  {
228  global $ilUser,$ilBench;
229 
230  unset($_SESSION['vis_references']);
231 
232  include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
233  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php';
234  $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery());
235  $qp->parse();
236  if(!strlen(trim($qp->getQuery())))
237  {
238  ilUtil::sendInfo($this->lng->txt('msg_no_search_string'));
239  $this->showSavedResults();
240  return false;
241  }
242 
243  $searcher = ilLuceneSearcher::getInstance($qp);
244  $searcher->search();
245 
246  // Filter results
247  $ilBench->start('Lucene','ResultFilter');
248  include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
249  include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
250  $filter = ilLuceneSearchResultFilter::getInstance($ilUser->getId());
251  $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
252  $filter->setCandidates($searcher->getResult());
253  $filter->filter();
254  $ilBench->stop('Lucene','ResultFilter');
255 
256  if($filter->getResultObjIds()) {
257  $searcher->highlight($filter->getResultObjIds());
258  }
259 
260  // Show results
261  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lucene_adv_search.html','Services/Search');
262  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
263  $presentation = new ilSearchResultPresentation($this);
264  $presentation->setResults($filter->getResultIds());
265  $presentation->setSearcher($searcher);
266 
267  // TODO: other handling required
268  $ilBench->start('Lucene','1500_fo');
269  $this->addPager($filter,'max_page');
270  $ilBench->stop('Lucene','1500_fo');
271  $presentation->setPreviousNext($this->prev_link, $this->next_link);
272 
273  if($presentation->render())
274  {
275  $this->tpl->setVariable('SEARCH_RESULTS',$presentation->getHTML(true));
276  }
277  else
278  {
279  ilUtil::sendInfo($this->lng->txt('search_no_match'));
280  }
281 
282  // and finally add search form
283  $this->initFormSearch();
284  $this->tpl->setVariable('SEARCH_TABLE',$this->form->getHTML());
285 
286  if($filter->getResultIds())
287  {
288  $this->fillAdminPanel();
289  }
290  }
291 
295  public function prepareOutput()
296  {
297  parent::prepareOutput();
298  $this->getTabs();
299  return true;
300  }
301 
305  protected function getTabs()
306  {
307  global $ilHelp;
308 
309  $ilHelp->setScreenIdComponent("src_luc");
310 
311  $this->tabs_gui->addTarget('search',$this->ctrl->getLinkTargetByClass('illucenesearchgui'));
312 
313  if(ilSearchSettings::getInstance()->isLuceneUserSearchEnabled())
314  {
315  $this->tabs_gui->addTarget('search_user',$this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
316  }
317 
318  if(
319  !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
320  $this->fields->getActiveFields())
321  {
322  $this->tabs_gui->addTarget('search_advanced',$this->ctrl->getLinkTarget($this));
323  }
324 
325  $this->tabs_gui->setTabActive('search_advanced');
326  }
327 
334  protected function initUserSearchCache()
335  {
336  global $ilUser;
337 
338  include_once('Services/Search/classes/class.ilUserSearchCache.php');
339  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
340  $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_ADVANCED);
341  if((int) $_GET['page_number'])
342  {
343  $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
344  }
345  if(isset($_POST['query']))
346  {
347  $this->search_cache->setQuery($_POST['query']);
348  }
349  }
350  protected function fillAdminPanel()
351  {
352  global $lng;
353 
354  $adm_view_cmp = $adm_cmds = $creation_selector = $adm_view = false;
355 
356  // admin panel commands
357  if ((count($this->admin_panel_commands) > 0))
358  {
359  foreach($this->admin_panel_commands as $cmd)
360  {
361  $this->tpl->setCurrentBlock("lucene_admin_panel_cmd");
362  $this->tpl->setVariable("LUCENE_PANEL_CMD", $cmd["cmd"]);
363  $this->tpl->setVariable("LUCENE_TXT_PANEL_CMD", $cmd["txt"]);
364  $this->tpl->parseCurrentBlock();
365  }
366 
367  $adm_cmds = true;
368  }
369  if ($adm_cmds)
370  {
371  $this->tpl->setCurrentBlock("lucene_adm_view_components");
372  $this->tpl->setVariable("LUCENE_ADM_IMG_ARROW", ilUtil::getImagePath("arrow_upright.svg"));
373  $this->tpl->setVariable("LUCENE_ADM_ALT_ARROW", $lng->txt("actions"));
374  $this->tpl->parseCurrentBlock();
375  $adm_view_cmp = true;
376  }
377 
378  // admin view button
379  if (is_array($this->admin_view_button))
380  {
381  if (is_array($this->admin_view_button))
382  {
383  $this->tpl->setCurrentBlock("lucene_admin_button");
384  $this->tpl->setVariable("LUCENE_ADMIN_MODE_LINK",
385  $this->admin_view_button["link"]);
386  $this->tpl->setVariable("LUCENE_TXT_ADMIN_MODE",
387  $this->admin_view_button["txt"]);
388  $this->tpl->parseCurrentBlock();
389  }
390  $this->tpl->setCurrentBlock("lucene_admin_view");
391  $this->tpl->parseCurrentBlock();
392  $adm_view = true;
393  }
394 
395  // creation selector
396  if (is_array($this->creation_selector))
397  {
398  $this->tpl->setCurrentBlock("lucene_add_commands");
399  if ($adm_cmds)
400  {
401  $this->tpl->setVariable("LUCENE_ADD_COM_WIDTH", 'width="1"');
402  }
403  $this->tpl->setVariable("LUCENE_SELECT_OBJTYPE_REPOS",
404  $this->creation_selector["options"]);
405  $this->tpl->setVariable("LUCENE_BTN_NAME_REPOS",
406  $this->creation_selector["command"]);
407  $this->tpl->setVariable("LUCENE_TXT_ADD_REPOS",
408  $this->creation_selector["txt"]);
409  $this->tpl->parseCurrentBlock();
410  $creation_selector = true;
411  }
412  if ($adm_view || $creation_selector)
413  {
414  $this->tpl->setCurrentBlock("lucene_adm_panel");
415  if ($adm_view_cmp)
416  {
417  $this->tpl->setVariable("LUCENE_ADM_TBL_WIDTH", 'width:"100%";');
418  }
419  $this->tpl->parseCurrentBlock();
420  }
421  }
422 
426  protected function addAdminPanelCommand($a_cmd, $a_txt)
427  {
428  $this->admin_panel_commands[] =
429  array("cmd" => $a_cmd, "txt" => $a_txt);
430  }
431 
435  protected function setAdminViewButton($a_link, $a_txt)
436  {
437  $this->admin_view_button =
438  array("link" => $a_link, "txt" => $a_txt);
439  }
440 
441  protected function setPageFormAction($a_action)
442  {
443  $this->page_form_action = $a_action;
444  }
445 }
446 ?>
$_SESSION["AccountId"]
This class represents a property form user interface.
GUI class for the workflow of copying objects.
$_GET["client_id"]
This class represents a section header in a property form.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
$cmd
Definition: sahs_server.php:35
static resetDetails()
reset details As long as static::resetDetails is not possible this method is final ...
prepareOutput()
Add admin panel command.
$errors fields
Definition: imgupload.php:52
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$section
Definition: Utf8Test.php:83
static _getInstance($a_usr_id)
Get singleton instance.
addPager($result, $a_session_key)
Add Pager.
Presentation of search results using object list gui.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$ilUser
Definition: imgupload.php:18
handleCommand($a_cmd)
Handle command.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
initUserSearchCache()
Init user search cache.
Create styles array
The data for the language used.
addAdminPanelCommand($a_cmd, $a_txt)
Add a command to the admin panel.
global $ilBench
Definition: ilias.php:18
setAdminViewButton($a_link, $a_txt)
Show admin view button.
static getInstance()
Get singleton instance.
$_POST["username"]