private function buildWarmer($search) { // This has a couple of compromises: $searcher = new Searcher($this->maint->getConnection(), 0, 50, null, array(), null); $searcher->setReturnQuery(true); $searcher->setResultsType(new FullTextResultsType(FullTextResultsType::HIGHLIGHT_ALL)); $searcher->limitSearchToLocalWiki(true); $query = $searcher->searchText($search, true)->getValue(); return $query['query']; }
/** * Let Elasticsearch take a crack at getting near matches once mediawiki has tried all kinds of variants. * @param string $term the original search term and all language variants * @param null|Title $titleResult resulting match. A Title if we found something, unchanged otherwise. * @return bool return false if we find something, true otherwise so mediawiki can try its default behavior */ public static function onSearchGetNearMatch($term, &$titleResult) { global $wgContLang; $title = Title::newFromText($term); if ($title === null) { return false; } $user = RequestContext::getMain()->getUser(); // Ask for the first 50 results we see. If there are more than that too bad. $searcher = new Searcher(self::getConnection(), 0, 50, null, array($title->getNamespace()), $user); if ($title->getNamespace() === NS_MAIN) { $searcher->updateNamespacesFromQuery($term); } else { $term = $title->getText(); } $searcher->setResultsType(new FancyTitleResultsType('near_match')); try { $status = $searcher->nearMatchTitleSearch($term); } catch (UsageException $e) { if (defined('MW_API')) { throw $e; } return true; } // There is no way to send errors or warnings back to the caller here so we have to make do with // only sending results back if there are results and relying on the logging done at the status // constrution site to log errors. if (!$status->isOK()) { return true; } $picker = new NearMatchPicker($wgContLang, $term, $status->getValue()); $best = $picker->pickBest(); if ($best) { $titleResult = $best; return false; } // Didn't find a result so let Mediawiki have a crack at it. return true; }