You are here

function rustemmer_search_preprocess in Russian stemming 7

Same name and namespace in other branches
  1. 6 rustemmer.module \rustemmer_search_preprocess()

Implements hook_search_preprocess().

1 call to rustemmer_search_preprocess()
SearchApiRussianStemmer::process in ./SearchApiRussianStemmer.php
Function that is ultimately called for all text by the standard implementation, and does nothing by default.

File

./rustemmer.module, line 32
Russian stemming algorith provided by Dr Martin Porter.

Code

function rustemmer_search_preprocess($text) {
  $words = $text;
  $words = str_replace('ё', 'е', $words);
  $words = str_replace('Ё', 'Е', $words);

  // Split words from noise and remove apostrophes.
  $words = preg_split('/([^' . RUSTEMMER_CHARS . ']+)/u', str_replace("'", '', $words), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  $stemmer = new RussianStemmer();

  // Process each word.
  $odd = TRUE;
  foreach ($words as $k => $word) {
    if ($odd) {
      $words[$k] = $stemmer
        ->stem_word($word);
    }
    $odd = !$odd;
  }

  // Put it all back together.
  return implode('', $words);
}