You are here

protected function SearchApiPorterStemmer::process in Search API 7

Function that is ultimately called for all text by the standard implementation, and does nothing by default.

Parameters

$value: The value to preprocess as a string. Can be manipulated directly, nothing has to be returned. Since this can be called for all value types, $value has to remain a string.

Overrides SearchApiAbstractProcessor::process

File

includes/processor_stemmer.inc, line 50
Contains SearchApiPorterStemmer and SearchApiPorter2.

Class

SearchApiPorterStemmer
Stems words to their roots.

Code

protected function process(&$value) {

  // Load custom exceptions.
  $exceptions = $this
    ->getExceptions();
  $words = preg_split('/[^\\p{L}\\p{N}]+/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
  $stemmed = array();
  foreach ($words as $i => $word) {
    if ($i % 2 == 0 && strlen($word)) {
      if (!isset($this->stems[$word])) {
        $stem = new SearchApiPorter2($word, $exceptions);
        $this->stems[$word] = $stem
          ->stem();
      }
      $stemmed[] = $this->stems[$word];
    }
    else {
      $stemmed[] = $word;
    }
  }
  $value = implode(' ', $stemmed);
}