本文整理汇总了PHP中ArticleSearchIndex::loadStopwords方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleSearchIndex::loadStopwords方法的具体用法?PHP ArticleSearchIndex::loadStopwords怎么用?PHP ArticleSearchIndex::loadStopwords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleSearchIndex
的用法示例。
在下文中一共展示了ArticleSearchIndex::loadStopwords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: join
/**
* Split a string into a clean array of keywords
* @param $text string
* @param $allowWildcards boolean
* @return array of keywords
*/
function &filterKeywords($text, $allowWildcards = false)
{
$minLength = Config::getVar('search', 'min_word_length');
$stopwords =& ArticleSearchIndex::loadStopwords();
// Join multiple lines into a single string
if (is_array($text)) {
$text = join("\n", $text);
}
$cleanText = Core::cleanVar($text);
// Remove punctuation
$cleanText = String::regexp_replace('/[!"\\#\\$%\'\\(\\)\\.\\?@\\[\\]\\^`\\{\\}~]/', '', $cleanText);
$cleanText = String::regexp_replace('/[\\+,:;&\\/<=>\\|\\\\]/', ' ', $cleanText);
$cleanText = String::regexp_replace('/[\\*]/', $allowWildcards ? '%' : ' ', $cleanText);
$cleanText = String::strtolower($cleanText);
// Split into words
$words = String::regexp_split('/\\s+/', $cleanText);
// FIXME Do not perform further filtering for some fields, e.g., author names?
// Remove stopwords
$keywords = array();
foreach ($words as $k) {
if (!isset($stopwords[$k]) && String::strlen($k) >= $minLength && !is_numeric($k)) {
$keywords[] = String::substr($k, 0, SEARCH_KEYWORD_MAX_LENGTH);
}
}
return $keywords;
}