You are here

protected function IgnoreCharacters::process in Search API 8

Processes a single string value.

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

Parameters

mixed $value: The value to preprocess, as a reference. Can be manipulated directly, nothing has to be returned. Since this can be called for all value types, $value has to remain the same type. The possible types for $value depend on shouldProcess().

Overrides FieldsProcessorPluginBase::process

See also

\Drupal\search_api\Processor\FieldsProcessorPluginBase::shouldProcess()

File

src/Plugin/search_api/processor/IgnoreCharacters.php, line 117

Class

IgnoreCharacters
Configure types of characters which should be ignored for searches.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

protected function process(&$value) {
  if ($this->configuration['ignorable']) {
    if (!isset($this->ignorable)) {
      $this->ignorable = str_replace('/', '\\/', $this->configuration['ignorable']);
    }
    $value = preg_replace('/' . $this->ignorable . '+/u', '', $value);
  }

  // Loop over the character sets and strip the characters from the text.
  foreach ($this->configuration['ignorable_classes'] as $character_set) {
    $regex = $this
      ->getFormatRegularExpression($character_set);
    if ($regex) {
      $value = preg_replace('/[' . $regex . ']+/u', '', $value);
    }
  }
}