當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SearchEngine::normalizeText方法代碼示例

本文整理匯總了PHP中SearchEngine::normalizeText方法的典型用法代碼示例。如果您正苦於以下問題:PHP SearchEngine::normalizeText方法的具體用法?PHP SearchEngine::normalizeText怎麽用?PHP SearchEngine::normalizeText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SearchEngine的用法示例。


在下文中一共展示了SearchEngine::normalizeText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getNormalizedTitle

 /**
  * Get a normalized string representation of a title suitable for
  * including in a search index
  *
  * @param SearchEngine $search
  * @return string A stripped-down title string ready for the search index
  */
 private function getNormalizedTitle(SearchEngine $search)
 {
     global $wgContLang;
     $ns = $this->title->getNamespace();
     $title = $this->title->getText();
     $lc = $search->legalSearchChars() . '&#;';
     $t = $wgContLang->normalizeForSearch($title);
     $t = preg_replace("/[^{$lc}]+/", ' ', $t);
     $t = $wgContLang->lc($t);
     # Handle 's, s'
     $t = preg_replace("/([{$lc}]+)'s( |\$)/", "\\1 \\1's ", $t);
     $t = preg_replace("/([{$lc}]+)s'( |\$)/", "\\1s ", $t);
     $t = preg_replace("/\\s+/", ' ', $t);
     if ($ns == NS_FILE) {
         $t = preg_replace("/ (png|gif|jpg|jpeg|ogg)\$/", "", $t);
     }
     return $search->normalizeText(trim($t));
 }
開發者ID:Acidburn0zzz,項目名稱:mediawiki,代碼行數:25,代碼來源:SearchUpdate.php

示例2: normalizeText

 /**
  * Converts some characters for MySQL's indexing to grok it correctly,
  * and pads short words to overcome limitations.
  */
 function normalizeText($string)
 {
     global $wgContLang;
     wfProfileIn(__METHOD__);
     $out = parent::normalizeText($string);
     // MySQL fulltext index doesn't grok utf-8, so we
     // need to fold cases and convert to hex
     $out = preg_replace_callback("/([\\xc0-\\xff][\\x80-\\xbf]*)/", array($this, 'stripForSearchCallback'), $wgContLang->lc($out));
     // And to add insult to injury, the default indexing
     // ignores short words... Pad them so we can pass them
     // through without reconfiguring the server...
     $minLength = $this->minSearchLength();
     if ($minLength > 1) {
         $n = $minLength - 1;
         $out = preg_replace("/\\b(\\w{1,{$n}})\\b/", "\$1u800", $out);
     }
     // Periods within things like hostnames and IP addresses
     // are also important -- we want a search for "example.com"
     // or "192.168.1.1" to work sanely.
     //
     // MySQL's search seems to ignore them, so you'd match on
     // "example.wikipedia.com" and "192.168.83.1" as well.
     $out = preg_replace("/(\\w)\\.(\\w|\\*)/u", "\$1u82e\$2", $out);
     wfProfileOut(__METHOD__);
     return $out;
 }
開發者ID:GodelDesign,項目名稱:Godel,代碼行數:30,代碼來源:SearchMySQL.php


注:本文中的SearchEngine::normalizeText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。