/**
  * @param int $user_id
  * @param int $mail_folder_id
  * @throws Exception
  */
 public function search($user_id, $mail_folder_id)
 {
     /**
      * @var $ilSetting ilSetting
      * @var $ilLog     ilLog
      * @var $ilBench   ilBenchmark
      */
     global $ilBench, $ilSetting, $ilLog;
     if (!$this->query_parser->getQuery()) {
         throw new ilException('mail_search_query_missing');
     }
     $ilBench->start('Mail', 'LuceneSearch');
     try {
         include_once 'Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
         $xml = ilRpcClientFactory::factory('RPCSearchHandler')->searchMail(CLIENT_ID . '_' . $ilSetting->get('inst_id', 0), (int) $user_id, (string) $this->query_parser->getQuery(), (int) $mail_folder_id);
     } catch (XML_RPC2_FaultException $e) {
         $ilBench->stop('Mail', 'LuceneSearch');
         $ilLog->write(__METHOD__ . ': ' . $e->getMessage());
         throw $e;
     } catch (Exception $e) {
         $ilBench->stop('Mail', 'LuceneSearch');
         $ilLog->write(__METHOD__ . ': ' . $e->getMessage());
         throw $e;
     }
     $ilBench->stop('Mail', 'LuceneSearch');
     include_once 'Services/Mail/classes/class.ilMailSearchLuceneResultParser.php';
     $parser = new ilMailSearchLuceneResultParser($this->result, $xml);
     $parser->parse();
 }
 /**
  * Performs better than standard like search on huge installations
  */
 public static function getLuceneList($a_str)
 {
     include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
     $qp = new ilLuceneQueryParser('title:' . $a_str . '*');
     $qp->parse();
     include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
     $searcher = ilLuceneSearcher::getInstance($qp);
     $searcher->setType(ilLuceneSearcher::TYPE_STANDARD);
     $searcher->search();
     $res = $searcher->getResult()->getCandidates();
     $max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength() ? ilSearchSettings::getInstance()->getAutoCompleteLength() : 10;
     $list = array();
     $num_entries = 0;
     foreach ($res as $res_obj_id) {
         if (self::checkObjectPermission($res_obj_id)) {
             $list[] = ilObject::_lookupTitle($res_obj_id, true);
             $num_entries++;
         }
         if ($num_entries >= $max_entries) {
             break;
         }
     }
     $i = 0;
     $result = array();
     foreach ($list as $entry) {
         $result[$i] = new stdClass();
         $result[$i]->value = '"' . $entry . '"';
         $i++;
     }
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     return ilJsonUtil::encode($result);
 }
 public function checkInput()
 {
     global $lng, $ilUser;
     $ok = parent::checkInput();
     $query = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
     if (!$ok or !strlen($query)) {
         return false;
     }
     include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
     try {
         ilLuceneQueryParser::validateQuery($query);
         return true;
     } catch (ilLuceneQueryParserException $e) {
         $this->setAlert($lng->txt($e->getMessage()));
         return false;
     }
 }
 /**
  * Constructor
  */
 public function __construct($a_query_data)
 {
     parent::__construct('');
     $this->field_definition = ilLuceneAdvancedSearchFields::getInstance();
     $this->query_data = $a_query_data;
 }
 /**
  * Perform search 
  */
 protected function performSearch()
 {
     include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
     include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
     $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
     $qp->parse();
     $searcher = ilLuceneSearcher::getInstance($qp);
     $searcher->setType(ilLuceneSearcher::TYPE_USER);
     $searcher->search();
     $this->showSearchForm();
     include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
     $user_table = new ilRepositoryUserResultTableGUI($this, 'performSearch', false, ilRepositoryUserResultTableGUI::TYPE_GLOBAL_SEARCH);
     $user_table->setLuceneResult($searcher->getResult());
     $user_table->parseUserIds($searcher->getResult()->getCandidates());
     $GLOBALS['tpl']->setVariable('SEARCH_RESULTS', $user_table->getHTML());
     return true;
 }
 /**
  * Perform search 
  */
 protected function performSearch()
 {
     global $ilUser, $ilBench;
     unset($_SESSION['vis_references']);
     $filter_query = '';
     if ($this->search_cache->getItemFilter() and ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
         $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions();
         foreach ((array) $this->search_cache->getItemFilter() as $obj => $value) {
             if (!$filter_query) {
                 $filter_query .= '+( ';
             } else {
                 $filter_query .= 'OR';
             }
             $filter_query .= ' ' . (string) $filter_settings[$obj]['filter'] . ' ';
         }
         $filter_query .= ') ';
     }
     // begin-patch mime_filter
     $mime_query = '';
     if ($this->search_cache->getMimeFilter() and ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
         $filter_settings = ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions();
         foreach ($this->search_cache->getMimeFilter() as $mime => $value) {
             if (!$mime_query) {
                 $mime_query .= '+( ';
             } else {
                 $mime_query .= 'OR';
             }
             $mime_query .= ' ' . (string) $filter_settings[$mime]['filter'] . ' ';
         }
         $mime_query .= ') ';
     }
     $filter_query = $filter_query . ' ' . $mime_query;
     include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
     include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
     $qp = new ilLuceneQueryParser($filter_query . ' +(' . $this->search_cache->getQuery() . ')');
     $qp->parse();
     $searcher = ilLuceneSearcher::getInstance($qp);
     $searcher->search();
     // Filter results
     include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
     include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
     $filter = ilLuceneSearchResultFilter::getInstance($ilUser->getId());
     $filter->addFilter(new ilLucenePathFilter($this->search_cache->getRoot()));
     $filter->setCandidates($searcher->getResult());
     $filter->filter();
     if ($filter->getResultObjIds()) {
         $searcher->highlight($filter->getResultObjIds());
     }
     // Show results
     $this->showSearchForm();
     include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
     $presentation = new ilSearchResultPresentation($this);
     $presentation->setResults($filter->getResultIds());
     $presentation->setSearcher($searcher);
     // TODO: other handling required
     $ilBench->start('Lucene', '1500_fo');
     $this->addPager($filter, 'max_page');
     $ilBench->stop('Lucene', '1500_fo');
     $presentation->setPreviousNext($this->prev_link, $this->next_link);
     if ($presentation->render()) {
         $this->tpl->setVariable('SEARCH_RESULTS', $presentation->getHTML(true));
     } else {
         ilUtil::sendInfo(sprintf($this->lng->txt('search_no_match_hint'), $this->search_cache->getQuery()));
     }
 }
 function searchObjects($sid, $types, $key, $combination, $user_id)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!is_array($types)) {
         return $this->__raiseError('Types must be an array of object types.', 'Client');
     }
     if ($combination != 'and' and $combination != 'or') {
         return $this->__raiseError('No valid combination given. Must be "and" or "or".', 'Client');
     }
     // begin-patch fm
     include_once './Services/Search/classes/class.ilSearchSettings.php';
     if (ilSearchSettings::getInstance()->enabledLucene()) {
         ilSearchSettings::getInstance()->setMaxHits(25);
         include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
         $query_parser = new ilLuceneQueryParser($key);
         $query_parser->parse();
         include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
         $searcher = ilLuceneSearcher::getInstance($query_parser);
         $searcher->search();
         include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
         include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
         $filter = ilLuceneSearchResultFilter::getInstance($user_id);
         $filter->setCandidates($searcher->getResult());
         $filter->filter();
         $result_ids = $filter->getResults();
         $objs = array();
         $objs[ROOT_FOLDER_ID] = ilObjectFactory::getInstanceByRefId(ROOT_FOLDER_ID, false);
         foreach ((array) $result_ids as $ref_id => $obj_id) {
             $obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
             if ($obj instanceof ilObject) {
                 $objs[] = $obj;
             }
         }
         include_once './Services/Search/classes/Lucene/class.ilLuceneHighlighterResultParser.php';
         $highlighter = new ilLuceneHighlighterResultParser();
         if ($filter->getResultObjIds()) {
             $highlighter = $searcher->highlight($filter->getResultObjIds());
         }
     } else {
         include_once './Services/Search/classes/class.ilQueryParser.php';
         $query_parser =& new ilQueryParser($key);
         #$query_parser->setMinWordLength(3);
         $query_parser->setCombination($combination == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
         $query_parser->parse();
         if (!$query_parser->validate()) {
             return $this->__raiseError($query_parser->getMessage(), 'Client');
         }
         #include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
         #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
         include_once './Services/Search/classes/Like/class.ilLikeObjectSearch.php';
         $object_search = new ilLikeObjectSearch($query_parser);
         $object_search->setFilter($types);
         $res =& $object_search->performSearch();
         if ($user_id) {
             $res->setUserId($user_id);
         }
         // begin-patch fm
         $res->setMaxHits(100);
         // begin-patch fm
         $res->filter(ROOT_FOLDER_ID, $combination == 'and' ? true : false);
         $counter = 0;
         $objs = array();
         foreach ($res->getUniqueResults() as $entry) {
             $obj = ilObjectFactory::getInstanceByRefId($entry['ref_id'], false);
             if ($obj instanceof ilObject) {
                 $objs[] = $obj;
             }
         }
     }
     if (!count($objs)) {
         //rku: todo: das ist nicht soap konform! - hier muss ein XML zurück geliefert werden
         return '';
     }
     include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
     $xml_writer = new ilObjectXMLWriter();
     // begin-patch fm
     if (ilSearchSettings::getInstance()->enabledLucene()) {
         $xml_writer->enableReferences(false);
         $xml_writer->setMode(ilObjectXmlWriter::MODE_SEARCH_RESULT);
         $xml_writer->setHighlighter($highlighter);
     }
     $xml_writer->enablePermissionCheck(true);
     if ($user_id) {
         $xml_writer->setUserId($user_id);
         $xml_writer->enableOperations(true);
     }
     $xml_writer->setObjects($objs);
     if ($xml_writer->start()) {
         #$GLOBALS['ilLog']->write(__METHOD__.': '.$xml_writer->xmlDumpMem(true));
         return $xml_writer->getXML();
     }
     return $this->__raiseError('Cannot create object xml !', 'Server');
 }
 /**
  * @throws LuceneQueryParserException
  */
 public static function validateQuery($a_query)
 {
     // TODO
     // First replace all quote characters
     #ilLuceneQueryParser::checkAllowedCharacters($a_query);
     #ilLuceneQueryParser::checkAsterisk($a_query);
     #ilLuceneQueryParser::checkAmpersands($a_query);
     ilLuceneQueryParser::checkCaret($a_query);
     ilLuceneQueryParser::checkSquiggle($a_query);
     #ilLuceneQueryParser::checkExclamationMark($a_query);
     #ilLuceneQueryParser::checkQuestionMark($a_query);
     ilLuceneQueryParser::checkParenthesis($a_query);
     #ilLuceneQueryParser::checkPlusMinus($a_query);
     #ilLuceneQueryParser::checkANDORNOT($a_query);
     ilLuceneQueryParser::checkQuotes($a_query);
     #ilLuceneQueryParser::checkColon($a_query);
     return true;
 }
 /**
  *  Search content that belongs to the current user and that meet the search criteria
  *
  */
 public function searchContentFile()
 {
     /**
      * @var $ilAccess ilAccessHandler
      */
     global $ilAccess;
     $this->initContentSearchForm();
     if ($this->csform->checkInput()) {
         $allowedExt = array('ppt', 'pptx', 'flv', 'swf', 'pdf', 'gif', 'jpg', 'png', 'mp3', 'html');
         $result = array();
         include_once './Services/Search/classes/class.ilSearchSettings.php';
         if (ilSearchSettings::getInstance()->enabledLucene()) {
             include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
             include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
             $qp = new ilLuceneQueryParser('+(type:file) ' . $this->csform->getInput('search_query'));
             $qp->parse();
             $searcher = ilLuceneSearcher::getInstance($qp);
             $searcher->search();
             include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
             include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
             $filter = ilLuceneSearchResultFilter::getInstance($this->user->getId());
             $filter->addFilter(new ilLucenePathFilter(ROOT_FOLDER_ID));
             $filter->setCandidates($searcher->getResult());
             $filter->filter();
             foreach ($filter->getResultIds() as $refId => $objId) {
                 $obj = ilObjectFactory::getInstanceByRefId($refId);
                 if (!in_array(strtolower($obj->getFileExtension()), $allowedExt)) {
                     continue;
                 }
                 if (!$ilAccess->checkAccessOfUser($this->user->getId(), 'read', '', $refId, '', $objId)) {
                     continue;
                 }
                 $result[$obj->getId()] = $obj->getId();
             }
         } else {
             include_once 'Services/Search/classes/class.ilQueryParser.php';
             $query_parser = new ilQueryParser($this->csform->getInput('search_query'));
             $query_parser->setCombination(QP_COMBINATION_OR);
             $query_parser->parse();
             if (!$query_parser->validate()) {
                 ilUtil::sendInfo($query_parser);
                 $this->csform->setValuesByPost();
                 return $this->showAddContent();
             }
             include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
             $object_search = new ilLikeObjectSearch($query_parser);
             $object_search->setFilter(array('file'));
             $res = $object_search->performSearch();
             $res->setUserId($this->user->getId());
             $res->setMaxHits(999999);
             $res->filter(ROOT_FOLDER_ID, false);
             $res->setRequiredPermission('read');
             foreach ($res->getUniqueResults() as $entry) {
                 $obj = ilObjectFactory::getInstanceByRefId($entry['ref_id']);
                 if (!in_array(strtolower($obj->getFileExtension()), $allowedExt)) {
                     continue;
                 }
                 $result[$obj->getId()] = $obj->getId();
             }
         }
         if (count($result) > 0) {
             $this->showFileSearchResult($result);
             $_SESSION['contents']['search_result'] = $result;
         } else {
             ilUtil::sendInfo($this->txt('files_matches_in_no_results'));
             $this->csform->setValuesByPost();
             $this->showAddContent();
         }
     } else {
         $this->csform->setValuesByPost();
         return $this->showAddContent();
     }
 }