public function AddHierarchy::preprocessIndexItems in Search API 8
Preprocesses search items for indexing.
Parameters
\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be preprocessed for indexing.
Overrides ProcessorPluginBase::preprocessIndexItems
File
- src/
Plugin/ search_api/ processor/ AddHierarchy.php, line 268
Class
- AddHierarchy
- Adds all ancestors' IDs to a hierarchical field.
Namespace
Drupal\search_api\Plugin\search_api\processorCode
public function preprocessIndexItems(array $items) {
/** @var \Drupal\search_api\Item\ItemInterface $item */
foreach ($items as $item) {
foreach ($this->configuration['fields'] as $field_id => $property_specifier) {
$field = $item
->getField($field_id);
if (!$field) {
continue;
}
list($entity_type_id, $property) = explode('-', $property_specifier);
foreach ($field
->getValues() as $entity_id) {
if ($entity_id instanceof TextValue) {
$entity_id = $entity_id
->getOriginalText();
}
if (is_scalar($entity_id)) {
try {
$this
->addHierarchyValues($entity_type_id, $entity_id, $property, $field);
} catch (\Exception $e) {
$vars = [
'%index' => $this->index
->label(),
'%field' => $field
->getLabel(),
'%field_id' => $field
->getFieldIdentifier(),
];
watchdog_exception('search_api', $e, '%type while trying to add hierarchy values to field %field (%field_id) on index %index: @message in %function (line %line of %file).', $vars);
continue;
}
}
}
}
}
}