You are here

public function Highlight::preIndexSave in Search API 8

Preprocesses the search index entity before it is saved.

This can, for example, be used to make sure fields needed by this processor are enabled on the index.

Overrides ProcessorPluginBase::preIndexSave

File

src/Plugin/search_api/processor/Highlight.php, line 105

Class

Highlight
Adds a highlighted excerpt to results and highlights returned fields.

Namespace

Drupal\search_api\Plugin\search_api\processor

Code

public function preIndexSave() {
  parent::preIndexSave();
  if (empty($this->configuration['exclude_fields'])) {
    return;
  }
  $renames = $this->index
    ->getFieldRenames();
  $selected_fields = array_flip($this->configuration['exclude_fields']);
  $renames = array_intersect_key($renames, $selected_fields);
  if ($renames) {
    $new_fields = array_keys(array_diff_key($selected_fields, $renames));
    $new_fields = array_merge($new_fields, array_values($renames));
    $this->configuration['exclude_fields'] = $new_fields;
  }
}