本文整理汇总了PHP中SearchEngine::create方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchEngine::create方法的具体用法?PHP SearchEngine::create怎么用?PHP SearchEngine::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchEngine
的用法示例。
在下文中一共展示了SearchEngine::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSearchEngine
static function getSearchEngine()
{
if (!self::$searchEngine) {
self::$searchEngine = SearchEngine::create();
}
return self::$searchEngine;
}
示例2: doUpdate
/**
* Perform actual update for the entry
*/
public function doUpdate()
{
global $wgDisableSearchUpdate;
if ($wgDisableSearchUpdate || !$this->id) {
return;
}
foreach (SearchEngine::getSearchTypes() as $type) {
$search = SearchEngine::create($type);
if (!$search->supports('search-update')) {
continue;
}
$normalTitle = $this->getNormalizedTitle($search);
if ($this->getLatestPage() === null) {
$search->delete($this->id, $normalTitle);
continue;
} elseif ($this->content === false) {
$search->updateTitle($this->id, $normalTitle);
continue;
}
$text = $search->getTextFromContent($this->title, $this->content);
if (!$search->textAlreadyUpdatedForIndex()) {
$text = self::updateText($text);
}
# Perform the actual update
$search->update($this->id, $normalTitle, $search->normalizeText($text));
}
}
示例3: doUpdate
/**
* Perform actual update for the entry
*/
public function doUpdate()
{
global $wgDisableSearchUpdate;
if ($wgDisableSearchUpdate || !$this->id) {
return;
}
wfProfileIn(__METHOD__);
$page = WikiPage::newFromId($this->id, WikiPage::READ_LATEST);
$indexTitle = Title::indexTitle($this->title->getNamespace(), $this->title->getText());
foreach (SearchEngine::getSearchTypes() as $type) {
$search = SearchEngine::create($type);
if (!$search->supports('search-update')) {
continue;
}
$normalTitle = $search->normalizeText($indexTitle);
if ($page === null) {
$search->delete($this->id, $normalTitle);
continue;
} elseif ($this->content === false) {
$search->updateTitle($this->id, $normalTitle);
continue;
}
$text = $search->getTextFromContent($this->title, $this->content);
if (!$search->textAlreadyUpdatedForIndex()) {
$text = self::updateText($text);
}
# Perform the actual update
$search->update($this->id, $normalTitle, $search->normalizeText($text));
}
wfProfileOut(__METHOD__);
}
示例4: execute
public function execute($parameters)
{
global $wgOut, $wgRequest, $wgDisableTextSearch, $wgScript;
$this->setHeaders();
list($limit, $offset) = wfCheckLimits();
$wgOut->addWikiText(wfMsgForContentNoTrans('proofreadpage_specialpage_text'));
$this->searchList = null;
$this->searchTerm = $wgRequest->getText('key');
$this->suppressSqlOffset = false;
if (!$wgDisableTextSearch) {
$self = $this->getTitle();
$wgOut->addHTML(Xml::openElement('form', array('action' => $wgScript)) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Xml::input('limit', false, $limit, array('type' => 'hidden')) . Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('proofreadpage_specialpage_legend')) . Xml::input('key', 20, $this->searchTerm) . ' ' . Xml::submitButton(wfMsg('ilsubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form'));
if ($this->searchTerm) {
$index_namespace = $this->index_namespace;
$index_ns_index = MWNamespace::getCanonicalIndex(strtolower(str_replace(' ', '_', $index_namespace)));
$searchEngine = SearchEngine::create();
$searchEngine->setLimitOffset($limit, $offset);
$searchEngine->setNamespaces(array($index_ns_index));
$searchEngine->showRedirects = false;
$textMatches = $searchEngine->searchText($this->searchTerm);
$escIndex = preg_quote($index_namespace, '/');
$this->searchList = array();
while ($result = $textMatches->next()) {
$title = $result->getTitle();
if ($title->getNamespace() == $index_ns_index) {
array_push($this->searchList, $title->getDBkey());
}
}
$this->suppressSqlOffset = true;
}
}
parent::execute($parameters);
}
示例5: setUp
protected function setUp()
{
parent::setUp();
if (!$this->isWikitextNS(NS_MAIN)) {
$this->markTestSkipped('Main namespace does not support wikitext.');
}
// Avoid special pages from extensions interferring with the tests
$this->setMwGlobals('wgSpecialPages', array());
$this->search = SearchEngine::create();
$this->search->setNamespaces(array());
}
示例6: run
/**
* @param ApiPageSet $resultPageSet
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
$offset = $params['offset'];
$searchEngine = SearchEngine::create();
$searchEngine->setLimitOffset($limit + 1, $offset);
$searchEngine->setNamespaces($namespaces);
$titles = $searchEngine->extractTitles($searchEngine->completionSearchWithVariants($search));
if ($resultPageSet) {
$resultPageSet->setRedirectMergePolicy(function (array $current, array $new) {
if (!isset($current['index']) || $new['index'] < $current['index']) {
$current['index'] = $new['index'];
}
return $current;
});
if (count($titles) > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
array_pop($titles);
}
$resultPageSet->populateFromTitles($titles);
foreach ($titles as $index => $title) {
$resultPageSet->setGeneratorData($title, array('index' => $index + $offset + 1));
}
} else {
$result = $this->getResult();
$count = 0;
foreach ($titles as $title) {
if (++$count > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
break;
}
$vals = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
if ($title->isSpecialPage()) {
$vals['special'] = true;
} else {
$vals['pageid'] = intval($title->getArticleId());
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
$result->addIndexedTagName(array('query', $this->getModuleName()), $this->getModulePrefix());
}
}
示例7: run
private function run($resultPageSet = null)
{
global $wgUser;
// XX Added to minimize perf issues with full text searching
if ($wgUser->isAnon()) {
$this->dieUsage("Search query api is disabled", 'param-search');
}
$params = $this->extractRequestParams();
$limit = $params['limit'];
$query = $params['search'];
if (is_null($query) || empty($query)) {
$this->dieUsage("empty search string is not allowed", 'param-search');
}
$search = SearchEngine::create();
$search->setLimitOffset($limit + 1, $params['offset']);
$search->setNamespaces($params['namespace']);
$search->showRedirects = $params['redirects'];
if ($params['what'] == 'text') {
$matches = $search->searchText($query);
} else {
$matches = $search->searchTitle($query);
}
$data = array();
$count = 0;
while ($result = $matches->next()) {
if (++$count > $limit) {
// We've reached the one extra which shows that there are additional items to be had. Stop here...
$this->setContinueEnumParameter('offset', $params['offset'] + $params['limit']);
break;
}
$title = $result->getTitle();
if (is_null($resultPageSet)) {
$data[] = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText());
} else {
$data[] = $title;
}
}
if (is_null($resultPageSet)) {
$result = $this->getResult();
$result->setIndexedTagName($data, 'p');
$result->addValue('query', $this->getModuleName(), $data);
} else {
$resultPageSet->populateFromTitles($data);
}
}
示例8: doUpdate
function doUpdate()
{
global $wgContLang, $wgDisableSearchUpdate;
if ($wgDisableSearchUpdate || !$this->mId) {
return false;
}
wfProfileIn(__METHOD__);
$search = SearchEngine::create();
$lc = SearchEngine::legalSearchChars() . '&#;';
if ($this->mText === false) {
$search->updateTitle($this->mId, $search->normalizeText(Title::indexTitle($this->mNamespace, $this->mTitle)));
wfProfileOut(__METHOD__);
return;
}
# Language-specific strip/conversion
$text = $wgContLang->normalizeForSearch($this->mText);
wfProfileIn(__METHOD__ . '-regexps');
$text = preg_replace("/<\\/?\\s*[A-Za-z][^>]*?>/", ' ', $wgContLang->lc(" " . $text . " "));
# Strip HTML markup
$text = preg_replace("/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD", "\\1\\2 \\2 \\2\\3", $text);
# Emphasize headings
# Strip external URLs
$uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
$protos = "http|https|ftp|mailto|news|gopher";
$pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|\$)/";
$text = preg_replace($pat, "\\1 \\3", $text);
$p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
$p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
$text = preg_replace($p1, "\\1 ", $text);
$text = preg_replace($p2, "\\1 \\3 ", $text);
# Internal image links
$pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
$text = preg_replace($pat2, " \\1 \\3", $text);
$text = preg_replace("/([^{$lc}])([{$lc}]+)]]([a-z]+)/", "\\1\\2 \\2\\3", $text);
# Handle [[game]]s
# Strip all remaining non-search characters
$text = preg_replace("/[^{$lc}]+/", " ", $text);
# Handle 's, s'
#
# $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
# $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
#
# These tail-anchored regexps are insanely slow. The worst case comes
# when Japanese or Chinese text (ie, no word spacing) is written on
# a wiki configured for Western UTF-8 mode. The Unicode characters are
# expanded to hex codes and the "words" are very long paragraph-length
# monstrosities. On a large page the above regexps may take over 20
# seconds *each* on a 1GHz-level processor.
#
# Following are reversed versions which are consistently fast
# (about 3 milliseconds on 1GHz-level processor).
#
$text = strrev(preg_replace("/ s'([{$lc}]+)/", " s'\\1 \\1", strrev($text)));
$text = strrev(preg_replace("/ 's([{$lc}]+)/", " s\\1", strrev($text)));
# Strip wiki '' and '''
$text = preg_replace("/''[']*/", " ", $text);
wfProfileOut(__METHOD__ . '-regexps');
wfRunHooks('SearchUpdate', array($this->mId, $this->mNamespace, $this->mTitle, &$text));
# Perform the actual update
$search->update($this->mId, $search->normalizeText(Title::indexTitle($this->mNamespace, $this->mTitle)), $search->normalizeText($text));
wfProfileOut(__METHOD__);
}
示例9: showResults
/**
* @param $fieldSet String
*/
public function showResults($fieldSet)
{
global $wgOut, $wgUser, $wgContLang, $wgScript, $wgSolrShowRelated, $wgSolrDebug;
wfProfileIn(__METHOD__);
$sk = $wgUser->getSkin();
$this->searchEngine = SearchEngine::create();
$search =& $this->searchEngine;
$search->setLimitOffset($this->limit, $this->offset);
$this->setupPage($fieldSet);
$t = Title::newFromText($fieldSet->getName());
//Do we have Title matches
$fields = $fieldSet->getFields();
//Build Solr query string form the fields
if (isset($fields['solrsearch'])) {
$query = $fields['solrsearch'];
} else {
$query = '';
}
$firsttime = true;
$fieldSeperator = $fieldSet->getFieldSeperator();
foreach ($fields as $key => $value) {
if ($key != 'solrsearch' && !empty($value)) {
if ($firsttime) {
$query = trim($query) . ' ' . trim(substr($key, 4)) . ':' . '(' . $value . ')';
$firsttime = false;
} else {
$query = trim($query) . " {$fieldSeperator} " . trim(substr($key, 4)) . ':' . '(' . $value . ')';
}
}
}
if (!empty($query)) {
$query .= $fieldSet->getQuery();
}
// TODO: More Exception Handling for Format Exceptions
try {
$titleMatches = $search->searchTitle($query);
if (!$titleMatches instanceof SearchResultTooMany) {
$textMatches = $search->searchText($query);
}
// did you mean... suggestions
if ($textMatches && $textMatches->hasSuggestion()) {
$st = SpecialPage::getTitleFor('SolrSearch');
# mirror Go/Search behaviour of original request ..
$didYouMeanParams = array('solrsearch' => $textMatches->getSuggestionQuery());
$stParams = $didYouMeanParams;
$suggestionSnippet = $textMatches->getSuggestionSnippet();
if ($suggestionSnippet == '') {
$suggestionSnippet = null;
}
$suggestLink = $sk->linkKnown($st, $suggestionSnippet, array(), $stParams);
$this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>';
}
} catch (Exception $exc) {
#Todo: Catch different Exceptions not just one for all
$textMatches = false;
$titleMatches = false;
$wgOut->addHTML('<p class="solr-error">' . wfMsg('solrstore-error') . '<p\\>');
if ($wgSolrDebug) {
$wgOut->addHTML('<p class="solr-error">' . $exc . '<p\\>');
}
}
// start rendering the page
$wgOut->addHtml(Xml::openElement('form', array('id' => 'solrsearch', 'method' => 'get', 'action' => $wgScript)));
$wgOut->addHtml(Xml::openElement('table', array('id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0)) . Xml::openElement('tr') . Xml::openElement('td') . "\n" . $this->shortDialog($fieldSet) . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::closeElement('table'));
// Sometimes the search engine knows there are too many hits
if ($titleMatches instanceof SearchResultTooMany) {
$wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
wfProfileOut(__METHOD__);
return;
}
$filePrefix = $wgContLang->getFormattedNsText(NS_FILE) . ':';
if (trim($query) === '' || $filePrefix === trim($query)) {
$wgOut->addHTML($this->formHeader(0, 0));
$wgOut->addHTML('</form>');
// Empty query -- straight view of search form
wfProfileOut(__METHOD__);
return;
}
// Get number of results
$titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
$textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
// Total initial query matches (possible false positives)
$num = $titleMatchesNum + $textMatchesNum;
// Get total actual results (after second filtering, if any)
$numTitleMatches = $titleMatches && !is_null($titleMatches->getTotalHits()) ? $titleMatches->getTotalHits() : $titleMatchesNum;
$numTextMatches = $textMatches && !is_null($textMatches->getTotalHits()) ? $textMatches->getTotalHits() : $textMatchesNum;
// get total number of results if backend can calculate it
$totalRes = 0;
if ($titleMatches && !is_null($titleMatches->getTotalHits())) {
$totalRes += $titleMatches->getTotalHits();
}
if ($textMatches && !is_null($textMatches->getTotalHits())) {
$totalRes += $textMatches->getTotalHits();
}
// show number of results and current offset
$wgOut->addHTML($this->formHeader($num, $totalRes));
$wgOut->addHtml(Xml::closeElement('form'));
//.........这里部分代码省略.........
示例10: initText
/**
* Lazy initialization of article text from DB
*/
protected function initText()
{
if (!isset($this->mText)) {
if ($this->mRevision != null) {
$this->mText = SearchEngine::create()->getTextFromContent($this->mTitle, $this->mRevision->getContent());
} else {
// TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
}
}
}
示例11: run
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$limit = $params['limit'];
$query = $params['search'];
$what = $params['what'];
if (strval($query) === '') {
$this->dieUsage("empty search string is not allowed", 'param-search');
}
$search = SearchEngine::create();
$search->setLimitOffset($limit + 1, $params['offset']);
$search->setNamespaces($params['namespace']);
$search->showRedirects = $params['redirects'];
if ($what == 'text') {
$matches = $search->searchText($query);
} elseif ($what == 'title') {
$matches = $search->searchTitle($query);
} else {
// We default to title searches; this is a terrible legacy
// of the way we initially set up the MySQL fulltext-based
// search engine with separate title and text fields.
// In the future, the default should be for a combined index.
$what = 'title';
$matches = $search->searchTitle($query);
// Not all search engines support a separate title search,
// for instance the Lucene-based engine we use on Wikipedia.
// In this case, fall back to full-text search (which will
// include titles in it!)
if (is_null($matches)) {
$what = 'text';
$matches = $search->searchText($query);
}
}
if (is_null($matches)) {
$this->dieUsage("{$what} search is disabled", "search-{$what}-disabled");
}
$titles = array();
$count = 0;
while ($result = $matches->next()) {
if (++$count > $limit) {
// We've reached the one extra which shows that there are additional items to be had. Stop here...
$this->setContinueEnumParameter('offset', $params['offset'] + $params['limit']);
break;
}
// Silently skip broken and missing titles
if ($result->isBrokenTitle() || $result->isMissingRevision()) {
continue;
}
$title = $result->getTitle();
if (is_null($resultPageSet)) {
$vals = array();
ApiQueryBase::addTitleInfo($vals, $title);
$fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $params['offset'] + $count - 1);
break;
}
} else {
$titles[] = $title;
}
}
if (is_null($resultPageSet)) {
$this->getResult()->setIndexedTagName_internal(array('query', $this->getModuleName()), 'p');
} else {
$resultPageSet->populateFromTitles($titles);
}
}
示例12: run
/**
* @param $resultPageSet ApiPageSet
* @return void
*/
private function run($resultPageSet = null)
{
global $wgContLang;
$params = $this->extractRequestParams();
// Extract parameters
$limit = $params['limit'];
$query = $params['search'];
$what = $params['what'];
$searchInfo = array_flip($params['info']);
$prop = array_flip($params['prop']);
// Create search engine instance and set options
$search = isset($params['backend']) && $params['backend'] != self::BACKEND_NULL_PARAM ? SearchEngine::create($params['backend']) : SearchEngine::create();
$search->setLimitOffset($limit + 1, $params['offset']);
$search->setNamespaces($params['namespace']);
$search->showRedirects = $params['redirects'];
$query = $search->transformSearchTerm($query);
$query = $search->replacePrefixes($query);
// Perform the actual search
if ($what == 'text') {
$matches = $search->searchText($query);
} elseif ($what == 'title') {
$matches = $search->searchTitle($query);
} elseif ($what == 'nearmatch') {
$matches = SearchEngine::getNearMatchResultSet($query);
} else {
// We default to title searches; this is a terrible legacy
// of the way we initially set up the MySQL fulltext-based
// search engine with separate title and text fields.
// In the future, the default should be for a combined index.
$what = 'title';
$matches = $search->searchTitle($query);
// Not all search engines support a separate title search,
// for instance the Lucene-based engine we use on Wikipedia.
// In this case, fall back to full-text search (which will
// include titles in it!)
if (is_null($matches)) {
$what = 'text';
$matches = $search->searchText($query);
}
}
if (is_null($matches)) {
$this->dieUsage("{$what} search is disabled", "search-{$what}-disabled");
} elseif ($matches instanceof Status && !$matches->isGood()) {
$this->dieUsage($matches->getWikiText(), 'search-error');
}
$apiResult = $this->getResult();
// Add search meta data to result
if (isset($searchInfo['totalhits'])) {
$totalhits = $matches->getTotalHits();
if ($totalhits !== null) {
$apiResult->addValue(array('query', 'searchinfo'), 'totalhits', $totalhits);
}
}
if (isset($searchInfo['suggestion']) && $matches->hasSuggestion()) {
$apiResult->addValue(array('query', 'searchinfo'), 'suggestion', $matches->getSuggestionQuery());
}
// Add the search results to the result
$terms = $wgContLang->convertForSearchResult($matches->termMatches());
$titles = array();
$count = 0;
$result = $matches->next();
while ($result) {
if (++$count > $limit) {
// We've reached the one extra which shows that there are
// additional items to be had. Stop here...
$this->setContinueEnumParameter('offset', $params['offset'] + $params['limit']);
break;
}
// Silently skip broken and missing titles
if ($result->isBrokenTitle() || $result->isMissingRevision()) {
$result = $matches->next();
continue;
}
$title = $result->getTitle();
if (is_null($resultPageSet)) {
$vals = array();
ApiQueryBase::addTitleInfo($vals, $title);
if (isset($prop['snippet'])) {
$vals['snippet'] = $result->getTextSnippet($terms);
}
if (isset($prop['size'])) {
$vals['size'] = $result->getByteSize();
}
if (isset($prop['wordcount'])) {
$vals['wordcount'] = $result->getWordCount();
}
if (isset($prop['timestamp'])) {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $result->getTimestamp());
}
if (!is_null($result->getScore()) && isset($prop['score'])) {
$vals['score'] = $result->getScore();
}
if (isset($prop['titlesnippet'])) {
$vals['titlesnippet'] = $result->getTitleSnippet($terms);
}
if (!is_null($result->getRedirectTitle())) {
//.........这里部分代码省略.........
示例13: prefixSearchSubpages
/**
* Return an array of subpages beginning with $search that this special page will accept.
*
* @param string $search Prefix to search for
* @param int $limit Maximum number of results to return (usually 10)
* @param int $offset Number of results to skip (usually 0)
* @return string[] Matching subpages
*/
public function prefixSearchSubpages($search, $limit, $offset)
{
$title = Title::newFromText($search, NS_FILE);
if (!$title || $title->getNamespace() !== NS_FILE) {
// No prefix suggestion outside of file namespace
return array();
}
$search = SearchEngine::create();
$search->setLimitOffset($limit, $offset);
// Autocomplete subpage the same as a normal search, but just for files
$search->setNamespaces(array(NS_FILE));
$result = $search->defaultPrefixSearch($search);
return array_map(function (Title $t) {
// Remove namespace in search suggestion
return $t->getText();
}, $result);
}
示例14: tagSearch
function tagSearch($action, $article)
{
if ($action != 'tagSearch') {
return true;
}
global $wgRequest, $wgOut;
wfProfileIn(__METHOD__);
$wgOut->setArticleBodyOnly(true);
$query = $wgRequest->getText('q');
$query = preg_replace("/[\"'<>]/", '', $query);
$search = SearchEngine::create();
$search->setLimitOffset(10, 0);
$search->setNamespaces(array(NS_MAIN));
$search->showRedirects = true;
$titleMatches = $search->searchTitle($query);
$numResults = $titleMatches ? $titleMatches->numRows() : 0;
if ($numResults > 0) {
$wgOut->addHTML(wfTagSearchShowMatches($titleMatches));
}
wfProfileOut(__METHOD__);
return false;
}
示例15: showResults
/**
* @param string $term
* @public
*/
function showResults($term)
{
$fname = 'SpecialSearch::showResults';
wfProfileIn($fname);
$this->setupPage($term);
global $wgOut;
$wgOut->addWikiMsg('searchresulttext');
if ('' === trim($term)) {
// Empty query -- straight view of search form
$wgOut->setSubtitle('');
$wgOut->addHTML($this->powerSearchBox($term));
$wgOut->addHTML($this->powerSearchFocus());
wfProfileOut($fname);
return;
}
global $wgDisableTextSearch;
if ($wgDisableTextSearch) {
global $wgForwardSearchUrl;
if ($wgForwardSearchUrl) {
$url = str_replace('$1', urlencode($term), $wgForwardSearchUrl);
$wgOut->redirect($url);
return;
}
global $wgInputEncoding;
$wgOut->addHTML(wfMsg('searchdisabled'));
$wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton'))));
wfProfileOut($fname);
return;
}
$search = SearchEngine::create();
$search->setLimitOffset($this->limit, $this->offset);
$search->setNamespaces($this->namespaces);
$search->showRedirects = $this->searchRedirects;
$titleMatches = $search->searchTitle($term);
// Sometimes the search engine knows there are too many hits
if ($titleMatches instanceof SearchResultTooMany) {
$wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
$wgOut->addHTML($this->powerSearchBox($term));
$wgOut->addHTML($this->powerSearchFocus());
wfProfileOut($fname);
return;
}
$textMatches = $search->searchText($term);
$num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0);
if ($num > 0) {
if ($num >= $this->limit) {
$top = wfShowingResults($this->offset, $this->limit);
} else {
$top = wfShowingResultsNum($this->offset, $this->limit, $num);
}
$wgOut->addHTML("<p>{$top}</p>\n");
}
if ($num || $this->offset) {
$prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), $num < $this->limit);
$wgOut->addHTML("<br />{$prevnext}\n");
}
if ($titleMatches) {
if ($titleMatches->numRows()) {
$wgOut->wrapWikiMsg("==\$1==\n", 'titlematches');
$wgOut->addHTML($this->showMatches($titleMatches));
} else {
$wgOut->wrapWikiMsg("==\$1==\n", 'notitlematches');
}
$titleMatches->free();
}
if ($textMatches) {
if ($textMatches->numRows()) {
$wgOut->wrapWikiMsg("==\$1==\n", 'textmatches');
$wgOut->addHTML($this->showMatches($textMatches));
} elseif ($num == 0) {
# Don't show the 'no text matches' if we received title matches
$wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches');
}
$textMatches->free();
}
if ($num == 0) {
$wgOut->addWikiMsg('nonefound');
}
if ($num || $this->offset) {
$wgOut->addHTML("<p>{$prevnext}</p>\n");
}
$wgOut->addHTML($this->powerSearchBox($term));
wfProfileOut($fname);
}