function porterstemmer_search_preprocess in Porter-Stemmer 6.2
Same name and namespace in other branches
- 8 porterstemmer.module \porterstemmer_search_preprocess()
- 5 porterstemmer.module \porterstemmer_search_preprocess()
- 6 porterstemmer.module \porterstemmer_search_preprocess()
- 7 porterstemmer.module \porterstemmer_search_preprocess()
Implementation of hook_search_preprocess().
Stems the words in $text, using the Porter Stemmer 2 algorithm.
File
- ./
porterstemmer.module, line 15 - This is an implementation of the Porter 2 Stemming algorithm from http://snowball.tartarus.org/algorithms/english/stemmer.html by Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Code
function porterstemmer_search_preprocess($text) {
// Convert text to lower case, and replace special apostrophes with regular
// apostrophes.
$text = drupal_strtolower(str_replace('’', "'", $text));
// Split into words
$words = preg_split('/(' . PORTERSTEMMER_BOUNDARY . '+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
if (!count($words)) {
return $text;
}
$has_pecl_stem = _porterstemmer_pecl_loaded();
// Process each word, skipping delimiters.
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0]);
foreach ($words as $k => $word) {
if ($isword) {
if ($has_pecl_stem) {
$words[$k] = stem_english($word);
}
else {
$words[$k] = porterstemmer_stem($word);
}
}
$isword = !$isword;
}
// Put it all back together (note that delimiters are in $words).
return implode('', $words);
}