本文整理汇总了PHP中SearchEngine::getNearMatch方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchEngine::getNearMatch方法的具体用法?PHP SearchEngine::getNearMatch怎么用?PHP SearchEngine::getNearMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchEngine
的用法示例。
在下文中一共展示了SearchEngine::getNearMatch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: goResult
/**
* If an exact title match can be found, jump straight ahead to it.
* @param string $term
* @public
*/
function goResult($term)
{
global $wgOut;
global $wgGoToEdit;
$this->setupPage($term);
# Try to go to page as entered.
$t = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($t)) {
return $this->showResults($term);
}
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch($term);
if (!is_null($t)) {
$wgOut->redirect($t->getFullURL());
return;
}
# No match, generate an edit URL
$t = Title::newFromText($term);
if (!is_null($t)) {
wfRunHooks('SpecialSearchNogomatch', array(&$t));
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$wgOut->redirect($t->getFullURL('action=edit'));
return;
}
}
if ($t->quickUserCan('create') && $t->quickUserCan('edit')) {
$wgOut->addWikiMsg('noexactmatch', wfEscapeWikiText($term));
} else {
$wgOut->addWikiMsg('noexactmatch-nocreate', wfEscapeWikiText($term));
}
return $this->showResults($term);
}
示例2: getNearMatch
/**
* Do not go to a near match if query prefixed with ~
*
* @param $searchterm String
* @return Title
*/
public static function getNearMatch( $searchterm ) {
if ( $searchterm[ 0 ] === '~' ) {
return null;
} else {
return parent::getNearMatch( $searchterm );
}
}
示例3: goResult
public function goResult($term)
{
global $wgOut;
# Try to go to page as entered.
$t = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($t)) {
return $this->showResults($term);
}
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch($term);
if (!is_null($t)) {
$wgOut->redirect($t->getFullURL());
return;
}
# No match, generate an edit URL
$t = Title::newFromText($term);
if (!is_null($t)) {
global $wgGoToEdit;
wfRunHooks('SpecialSearchNogomatch', array(&$t));
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$wgOut->redirect($t->getFullURL(array('action' => 'edit')));
return;
}
}
}
示例4: efGoToCategory_SpecialSearchNogomatch
function efGoToCategory_SpecialSearchNogomatch($t)
{
global $wgOut, $wgRequest;
$term = $wgRequest->getText('search');
if (!empty($term) && strpos('category:', strtolower($term)) !== 0) {
$term = "Category:{$term}";
}
$title = SearchEngine::getNearMatch($term);
if (!is_null($title)) {
$wgOut->redirect($title->getFullURL());
}
return true;
}
示例5: goResult
/**
* If an exact title match can be found, jump straight ahead to it.
*
* @param string $term
*/
public function goResult($term)
{
$this->setupPage($term);
# Try to go to page as entered.
$title = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($title)) {
$this->showResults($term);
return;
}
# If there's an exact or very near match, jump right there.
$title = SearchEngine::getNearMatch($term);
if (!is_null($title)) {
$this->getOutput()->redirect($title->getFullURL());
return;
}
# No match, generate an edit URL
$title = Title::newFromText($term);
if (!is_null($title)) {
wfRunHooks('SpecialSearchNogomatch', array(&$title));
}
$this->showResults($term);
}
示例6: getNearMatchInternal
/**
* Really find the title match.
* @return null|\Title
*/
private static function getNearMatchInternal($searchterm)
{
global $wgContLang, $wgEnableSearchContributorsByIP;
$allSearchTerms = array($searchterm);
if ($wgContLang->hasVariants()) {
$allSearchTerms = array_merge($allSearchTerms, $wgContLang->autoConvertToAllVariants($searchterm));
}
$titleResult = null;
if (!wfRunHooks('SearchGetNearMatchBefore', array($allSearchTerms, &$titleResult))) {
return $titleResult;
}
foreach ($allSearchTerms as $term) {
# Exact match? No need to look further.
$title = Title::newFromText($term);
if (is_null($title)) {
return null;
}
if ($title->isSpecialPage() || $title->isExternal() || $title->exists()) {
return $title;
}
# See if it still otherwise has content is some sane sense
$page = WikiPage::factory($title);
if ($page->hasViewableContent()) {
return $title;
}
# Now try all lower case (i.e. first letter capitalized)
#
$title = Title::newFromText($wgContLang->lc($term));
if ($title && $title->exists()) {
return $title;
}
# Now try capitalized string
#
$title = Title::newFromText($wgContLang->ucwords($term));
if ($title && $title->exists()) {
return $title;
}
# Now try all upper case
#
$title = Title::newFromText($wgContLang->uc($term));
if ($title && $title->exists()) {
return $title;
}
# Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
$title = Title::newFromText($wgContLang->ucwordbreaks($term));
if ($title && $title->exists()) {
return $title;
}
// Give hooks a chance at better match variants
$title = null;
if (!wfRunHooks('SearchGetNearMatch', array($term, &$title))) {
return $title;
}
}
$title = Title::newFromText($searchterm);
# Entering an IP address goes to the contributions page
if ($wgEnableSearchContributorsByIP) {
if ($title->getNamespace() == NS_USER && User::isIP($title->getText()) || User::isIP(trim($searchterm))) {
return SpecialPage::getTitleFor('Contributions', $title->getDBkey());
}
}
# Entering a user goes to the user page whether it's there or not
if ($title->getNamespace() == NS_USER) {
return $title;
}
# Go to images that exist even if there's no local page.
# There may have been a funny upload, or it may be on a shared
# file repository such as Wikimedia Commons.
if ($title->getNamespace() == NS_FILE) {
$image = wfFindFile($title);
if ($image) {
return $title;
}
}
# MediaWiki namespace? Page may be "implied" if not customized.
# Just return it, with caps forced as the message system likes it.
if ($title->getNamespace() == NS_MEDIAWIKI) {
return Title::makeTitle(NS_MEDIAWIKI, $wgContLang->ucfirst($title->getText()));
}
# Quoted term? Try without the quotes...
$matches = array();
if (preg_match('/^"([^"]+)"$/', $searchterm, $matches)) {
return SearchEngine::getNearMatch($matches[1]);
}
return null;
}
示例7: goResult
/**
* If an exact title match can be found, jump straight ahead to it.
*
* @param $term String
*/
public function goResult($term)
{
$this->setupPage($term);
# Try to go to page as entered.
$t = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($t)) {
return $this->showResults($term);
}
$searchWithNamespace = $t->getNamespace() != 0 ? true : false;
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch($term);
if (!wfRunHooks('SpecialSearchGo', array(&$t, &$term))) {
# Hook requested termination
return;
}
if (!is_null($t) && ($searchWithNamespace || $t->getNamespace() == NS_MAIN || $t->getNamespace() == NS_CATEGORY)) {
// Wikia change (ADi): hook call added
wfRunHooks('SpecialSearchIsgomatch', array(&$t, $term));
$this->getOutput()->redirect($t->getFullURL());
return;
}
# No match, generate an edit URL
$t = Title::newFromText($term);
if (!is_null($t)) {
global $wgGoToEdit;
wfRunHooks('SpecialSearchNogomatch', array(&$t));
wfDebugLog('nogomatch', $t->getText(), false);
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$this->getOutput()->redirect($t->getFullURL(array('action' => 'edit')));
return;
}
}
return $this->showResults($term);
}
示例8: goResult
/**
* If an exact title match can be found, jump straight ahead to it.
*
* @param $term String
*/
public function goResult($term)
{
$this->setupPage($term);
# Try to go to page as entered.
$title = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($title)) {
$this->showResults($term);
return;
}
# If there's an exact or very near match, jump right there.
$title = SearchEngine::getNearMatch($term);
if (!wfRunHooks('SpecialSearchGo', array(&$title, &$term))) {
# Hook requested termination
return;
}
if (!is_null($title)) {
$this->getOutput()->redirect($title->getFullURL());
return;
}
# No match, generate an edit URL
$title = Title::newFromText($term);
if (!is_null($title)) {
global $wgGoToEdit;
wfRunHooks('SpecialSearchNogomatch', array(&$title));
wfDebugLog('nogomatch', $title->getFullText(), 'private');
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$this->getOutput()->redirect($title->getFullURL(array('action' => 'edit')));
return;
}
}
$this->showResults($term);
}
示例9: getNearMatch
/**
* If an exact title match can be find, or a very slightly close match,
* return the title. If no match, returns NULL.
*
* @param string $term
* @return Title
*/
public static function getNearMatch($searchterm)
{
global $wgContLang;
$allSearchTerms = array($searchterm);
if ($wgContLang->hasVariants()) {
$allSearchTerms = array_merge($allSearchTerms, $wgContLang->convertLinkToAllVariants($searchterm));
}
foreach ($allSearchTerms as $term) {
# Exact match? No need to look further.
$title = Title::newFromText($term);
if (is_null($title)) {
return NULL;
}
if ($title->getNamespace() == NS_SPECIAL || $title->exists()) {
return $title;
}
# Now try all lower case (i.e. first letter capitalized)
#
$title = Title::newFromText($wgContLang->lc($term));
if ($title->exists()) {
return $title;
}
# Now try capitalized string
#
$title = Title::newFromText($wgContLang->ucwords($term));
if ($title->exists()) {
return $title;
}
# Now try all upper case
#
$title = Title::newFromText($wgContLang->uc($term));
if ($title->exists()) {
return $title;
}
# Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
$title = Title::newFromText($wgContLang->ucwordbreaks($term));
if ($title->exists()) {
return $title;
}
global $wgCapitalLinks, $wgContLang;
if (!$wgCapitalLinks) {
// Catch differs-by-first-letter-case-only
$title = Title::newFromText($wgContLang->ucfirst($term));
if ($title->exists()) {
return $title;
}
$title = Title::newFromText($wgContLang->lcfirst($term));
if ($title->exists()) {
return $title;
}
}
// Give hooks a chance at better match variants
$title = null;
if (!wfRunHooks('SearchGetNearMatch', array($term, &$title))) {
return $title;
}
}
$title = Title::newFromText($searchterm);
# Entering an IP address goes to the contributions page
if ($title->getNamespace() == NS_USER && User::isIP($title->getText()) || User::isIP(trim($searchterm))) {
return SpecialPage::getTitleFor('Contributions', $title->getDBkey());
}
# Entering a user goes to the user page whether it's there or not
if ($title->getNamespace() == NS_USER) {
return $title;
}
# Go to images that exist even if there's no local page.
# There may have been a funny upload, or it may be on a shared
# file repository such as Wikimedia Commons.
if ($title->getNamespace() == NS_IMAGE) {
$image = wfFindFile($title);
if ($image) {
return $title;
}
}
# MediaWiki namespace? Page may be "implied" if not customized.
# Just return it, with caps forced as the message system likes it.
if ($title->getNamespace() == NS_MEDIAWIKI) {
return Title::makeTitle(NS_MEDIAWIKI, $wgContLang->ucfirst($title->getText()));
}
# Quoted term? Try without the quotes...
$matches = array();
if (preg_match('/^"([^"]+)"$/', $searchterm, $matches)) {
return SearchEngine::getNearMatch($matches[1]);
}
return NULL;
}
示例10: getNearMatch
/**
* If an exact title match can be find, or a very slightly close match,
* return the title. If no match, returns NULL.
*
* @static
* @param string $term
* @return Title
* @access private
*/
function getNearMatch($term)
{
# Exact match? No need to look further.
$title = Title::newFromText($term);
if (is_null($title)) {
return NULL;
}
if ($title->getNamespace() == NS_SPECIAL || $title->exists()) {
return $title;
}
# Now try all lower case (i.e. first letter capitalized)
#
$title = Title::newFromText(strtolower($term));
if ($title->exists()) {
return $title;
}
# Now try capitalized string
#
$title = Title::newFromText(ucwords(strtolower($term)));
if ($title->exists()) {
return $title;
}
# Now try all upper case
#
$title = Title::newFromText(strtoupper($term));
if ($title->exists()) {
return $title;
}
global $wgCapitalLinks, $wgContLang;
if (!$wgCapitalLinks) {
// Catch differs-by-first-letter-case-only
$title = Title::newFromText($wgContLang->ucfirst($term));
if ($title->exists()) {
return $title;
}
$title = Title::newFromText($wgContLang->lcfirst($term));
if ($title->exists()) {
return $title;
}
}
$title = Title::newFromText($term);
# Entering an IP address goes to the contributions page
if ($title->getNamespace() == NS_USER && User::isIP($title->getText()) || User::isIP(trim($term))) {
return Title::makeTitle(NS_SPECIAL, "Contributions/" . $title->getDbkey());
}
# Entering a user goes to the user page whether it's there or not
if ($title->getNamespace() == NS_USER) {
return $title;
}
# Quoted term? Try without the quotes...
if (preg_match('/^"([^"]+)"$/', $term, $matches)) {
return SearchEngine::getNearMatch($matches[1]);
}
return NULL;
}
示例11: goResult
/**
* If an exact title match can be found, jump straight ahead to
* @param string $term
* @access public
*/
function goResult($term)
{
global $wgOut;
global $wgGoToEdit;
$this->setupPage($term);
# Try to go to page as entered.
#
$t = Title::newFromText($term);
# If the string cannot be used to create a title
if (is_null($t)) {
return $this->showResults($term);
}
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch($term);
if (!is_null($t)) {
$wgOut->redirect($t->getFullURL());
return;
}
# No match, generate an edit URL
$t = Title::newFromText($term);
if (is_null($t)) {
$editurl = '';
# hrm...
} else {
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$wgOut->redirect($t->getFullURL('action=edit'));
return;
} else {
$editurl = $t->escapeLocalURL('action=edit');
}
}
$wgOut->addWikiText(wfMsg('nogomatch', ":{$term}"));
return $this->showResults($term);
}
示例12: getArticleMatchForTermAndNamespaces
/**
* Provided a string, uses MediaWiki's ability to find article matches to instantiate a Wikia Search Article Match.
* @param string $term
* @param array $namespaces
* @return \Wikia\Search\Match\Article|NULL
*/
public function getArticleMatchForTermAndNamespaces($term, array $namespaces)
{
$articleMatch = null;
$searchEngine = new \SearchEngine();
$title = $searchEngine->getNearMatch($term);
$articleId = $title !== null ? $title->getArticleId() : 0;
if ($articleId > 0 && in_array($title->getNamespace(), $namespaces)) {
$this->getPageFromPageId($articleId);
$articleMatch = new \Wikia\Search\Match\Article($title->getArticleId(), $this, $term);
}
return $articleMatch;
}
示例13: getNearMatch
/**
* If an exact title match can be find, or a very slightly close match,
* return the title. If no match, returns NULL.
*
* @static
* @param string $term
* @return Title
* @private
*/
function getNearMatch($searchterm)
{
global $wgContLang;
$allSearchTerms = array($searchterm);
if ($wgContLang->hasVariants()) {
$allSearchTerms = array_merge($allSearchTerms, $wgContLang->convertLinkToAllVariants($searchterm));
}
foreach ($allSearchTerms as $term) {
# Exact match? No need to look further.
$title = Title::newFromText($term);
if (is_null($title)) {
return NULL;
}
if ($title->getNamespace() == NS_SPECIAL || $title->exists()) {
return $title;
}
# Now try all lower case (i.e. first letter capitalized)
#
$title = Title::newFromText($wgContLang->lc($term));
if ($title->exists()) {
return $title;
}
# Now try capitalized string
#
$title = Title::newFromText($wgContLang->ucwords($term));
if ($title->exists()) {
return $title;
}
# Now try all upper case
#
$title = Title::newFromText($wgContLang->uc($term));
if ($title->exists()) {
return $title;
}
# Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
$title = Title::newFromText($wgContLang->ucwordbreaks($term));
if ($title->exists()) {
return $title;
}
global $wgCapitalLinks, $wgContLang;
if (!$wgCapitalLinks) {
// Catch differs-by-first-letter-case-only
$title = Title::newFromText($wgContLang->ucfirst($term));
if ($title->exists()) {
return $title;
}
$title = Title::newFromText($wgContLang->lcfirst($term));
if ($title->exists()) {
return $title;
}
}
}
$title = Title::newFromText($searchterm);
# Entering an IP address goes to the contributions page
if ($title->getNamespace() == NS_USER && User::isIP($title->getText()) || User::isIP(trim($searchterm))) {
return SpecialPage::getTitleFor('Contributions', $title->getDbkey());
}
# Entering a user goes to the user page whether it's there or not
if ($title->getNamespace() == NS_USER) {
return $title;
}
# Quoted term? Try without the quotes...
$matches = array();
if (preg_match('/^"([^"]+)"$/', $searchterm, $matches)) {
return SearchEngine::getNearMatch($matches[1]);
}
return NULL;
}
示例14: execute
function execute($par)
{
global $wgRequest, $wgOut, $wgTitle, $wgContLang, $wgUser, $wgScriptPath, $wgLuceneDisableTitleMatches, $wgLuceneDisableSuggestions, $wgUser;
global $wgGoToEdit;
wfLoadExtensionMessages('LuceneSearch');
$fname = 'LuceneSearch::execute';
wfProfileIn($fname);
$this->setHeaders();
$wgOut->addHTML('<!-- titlens = ' . $wgTitle->getNamespace() . '-->');
foreach (SearchEngine::searchableNamespaces() as $ns => $name) {
if ($wgRequest->getCheck('ns' . $ns)) {
$this->namespaces[] = $ns;
}
}
if (count($this->namespaces) == 0) {
foreach (SearchEngine::searchableNamespaces() as $ns => $name) {
if ($wgUser->getOption('searchNs' . $ns)) {
$this->namespaces[] = $ns;
}
}
if (count($this->namespaces) == 0) {
global $wgNamespacesToBeSearchedDefault;
foreach ($wgNamespacesToBeSearchedDefault as $ns => $searchit) {
if ($searchit) {
$this->namespaces[] = $ns;
}
}
}
}
$bits = split('/', $wgRequest->getVal('title'), 2);
if (!empty($bits[1])) {
$q = str_replace('_', ' ', $bits[1]);
} else {
$q = $wgRequest->getText('search');
}
list($limit, $offset) = $wgRequest->getLimitOffset(LS_PER_PAGE, 'searchlimit');
if ($wgRequest->getVal('gen') == 'titlematch') {
$this->sendTitlePrefixes($q, $limit);
wfProfileOut($fname);
return;
}
$this->mSkin =& $wgUser->getSkin();
if (!$wgLuceneDisableSuggestions) {
$wgOut->addHTML($this->makeSuggestJS());
}
$wgOut->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen,projection', 'href' => $wgScriptPath . '/extensions/LuceneSearch/lucenesearch.css'));
$wgOut->addWikiText(wfMsg('searchresulttext'));
$wgOut->addHTML($this->showShortDialog($q));
if ($q === false || strlen($q) == 0) {
// No search active. Put input focus in the search box.
$wgOut->addHTML($this->makeFocusJS());
} else {
if (!$wgRequest->getText('fulltext')) {
$t = SearchEngine::getNearMatch($q);
if (!is_null($t)) {
$wgOut->redirect($t->getFullURL());
wfProfileOut($fname);
return;
}
}
# No match, generate an edit URL
$t = Title::newFromText($q);
if (!$wgRequest->getText('go') || is_null($t)) {
$editurl = '';
# hrm...
} else {
wfRunHooks('SpecialSearchNogomatch', array(&$t));
# If the feature is enabled, go straight to the edit page
if ($wgGoToEdit) {
$wgOut->redirect($t->getFullURL('action=edit'));
return;
}
if ($t->quickUserCan('create') && $t->quickUserCan('edit')) {
$wgOut->addWikiText(wfMsg('noexactmatch', $t->getPrefixedText()));
} else {
$wgOut->addWikiText(wfMsg('noexactmatch-nocreate', $t->getPrefixedText()));
}
}
$case = 'ignore';
# Replace localized namespace prefixes (from lucene-search 2.0)
global $wgLuceneSearchVersion;
if ($wgLuceneSearchVersion >= 2) {
$searchq = $this->replacePrefixes($q);
if ($wgRequest->getText('fulltext') == wfMsg('searchexactcase')) {
$case = 'exact';
}
} else {
$searchq = $q;
}
global $wgDisableTextSearch;
if (!$wgDisableTextSearch) {
$results = LuceneSearchSet::newFromQuery('search', $searchq, $this->namespaces, $limit, $offset, $case);
}
if ($wgDisableTextSearch || $results === false) {
if ($wgDisableTextSearch) {
$wgOut->addHTML(wfMsg('searchdisabled'));
} else {
$wgOut->addWikiText(wfMsg('lucenefallback'));
}
$wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($q), 'utf-8', htmlspecialchars(wfMsg('search'))));
//.........这里部分代码省略.........