/** * * @param int $a_user_id user_id * @return * @static */ public static function getInstance($a_user_id) { if (self::$instance == null) { return self::$instance = new ilLuceneSearchResultFilter($a_user_id); } return self::$instance; }
/** * 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())); } }
/** * 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(); } }
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'); }
/** * Perform search */ protected function performSearch() { global $ilUser, $ilBench; unset($_SESSION['vis_references']); include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php'; include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedQueryParser.php'; $qp = new ilLuceneAdvancedQueryParser($this->search_cache->getQuery()); $qp->parse(); if (!strlen(trim($qp->getQuery()))) { ilUtil::sendInfo($this->lng->txt('msg_no_search_string')); $this->showSavedResults(); return false; } $searcher = ilLuceneSearcher::getInstance($qp); $searcher->search(); // Filter results $ilBench->start('Lucene', 'ResultFilter'); 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(); $ilBench->stop('Lucene', 'ResultFilter'); if ($filter->getResultObjIds()) { $searcher->highlight($filter->getResultObjIds()); } // Show results $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_adv_search.html', 'Services/Search'); 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($this->lng->txt('search_no_match')); } // and finally add search form $this->initFormSearch(); $this->tpl->setVariable('SEARCH_TABLE', $this->form->getHTML()); if ($filter->getResultIds()) { $this->fillAdminPanel(); } }