class SearchApiPorterStemmer in Search API 7
Stems words to their roots.
Hierarchy
- class \SearchApiAbstractProcessor implements SearchApiProcessorInterface
- class \SearchApiPorterStemmer
Expanded class hierarchy of SearchApiPorterStemmer
1 string reference to 'SearchApiPorterStemmer'
- search_api_search_api_processor_info in ./
search_api.module - Implements hook_search_api_processor_info().
File
- includes/
processor_stemmer.inc, line 11 - Contains SearchApiPorterStemmer and SearchApiPorter2.
View source
class SearchApiPorterStemmer extends SearchApiAbstractProcessor {
/**
* Static cache for already generated stems.
*
* @var array
*/
protected $stems = array();
/**
* {@inheritdoc}
*/
public function configurationForm() {
$form = parent::configurationForm();
$args = array(
'@algorithm' => url('http://snowball.tartarus.org/algorithms/english/stemmer.html'),
);
$form += array(
'help' => array(
'#markup' => '<p>' . t('Optionally, provide an exclusion list to override the stemmer algorithm. (<a href="@algorithm">Read about the algorithm</a>.)', $args) . '</p>',
),
'exceptions' => array(
'#type' => 'textarea',
'#title' => t('Exceptions'),
'#description' => t('Enter exceptions in the form of WORD=STEM, where "WORD" is the term entered and "STEM" is the resulting stem. List each exception on a separate line.'),
'#default_value' => "texan=texa",
),
);
if (!empty($this->options['exceptions'])) {
$form['exceptions']['#default_value'] = $this->options['exceptions'];
}
return $form;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* Retrieves the processor's configured exceptions.
*
* @return string[]
* An associative array of exceptions, with words as keys and stems as their
* replacements.
*/
protected function getExceptions() {
if (!empty($this->options['exceptions'])) {
$exceptions = parse_ini_string($this->options['exceptions'], TRUE);
return is_array($exceptions) ? $exceptions : array();
}
return array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiAbstractProcessor:: |
protected | property | ||
SearchApiAbstractProcessor:: |
protected | property | ||
SearchApiAbstractProcessor:: |
public | function |
Submit callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface:: |
|
SearchApiAbstractProcessor:: |
public | function |
Validation callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface:: |
4 |
SearchApiAbstractProcessor:: |
protected | function | Internal helper function for imploding tokens into a single string. | |
SearchApiAbstractProcessor:: |
protected | function | Internal helper function for normalizing tokens. | |
SearchApiAbstractProcessor:: |
public | function |
Does nothing. Overrides SearchApiProcessorInterface:: |
2 |
SearchApiAbstractProcessor:: |
public | function |
Calls processField() for all appropriate fields. Overrides SearchApiProcessorInterface:: |
|
SearchApiAbstractProcessor:: |
public | function |
Calls processKeys() for the keys and processFilters() for the filters. Overrides SearchApiProcessorInterface:: |
1 |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing field data. | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single text element in a field. The default implementation just calls process(). | 2 |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing query filters. | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single filter value. The default implementation just calls process(). | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single search keyword. The default implementation just calls process(). | |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing search keys. | |
SearchApiAbstractProcessor:: |
public | function |
Check whether this processor is applicable for a certain index. Overrides SearchApiProcessorInterface:: |
|
SearchApiAbstractProcessor:: |
protected | function | Determines whether to process data from the given field. | |
SearchApiAbstractProcessor:: |
protected | function | Determines whether fields of the given type should normally be processed. | |
SearchApiAbstractProcessor:: |
public | function |
Constructor, saving its arguments into properties. Overrides SearchApiProcessorInterface:: |
2 |
SearchApiPorterStemmer:: |
protected | property | Static cache for already generated stems. | |
SearchApiPorterStemmer:: |
public | function |
Display a form for configuring this processor.
Since forcing users to specify options for disabled processors makes no
sense, none of the form elements should have the '#required' attribute set. Overrides SearchApiAbstractProcessor:: |
|
SearchApiPorterStemmer:: |
protected | function | Retrieves the processor's configured exceptions. | |
SearchApiPorterStemmer:: |
protected | function |
Function that is ultimately called for all text by the standard
implementation, and does nothing by default. Overrides SearchApiAbstractProcessor:: |