public function DateRange::preprocessIndexItems in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/processor/DateRange.php \Drupal\search_api_solr\Plugin\search_api\processor\DateRange::preprocessIndexItems()
- 4.x src/Plugin/search_api/processor/DateRange.php \Drupal\search_api_solr\Plugin\search_api\processor\DateRange::preprocessIndexItems()
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/ DateRange.php, line 27
Class
- DateRange
- Add date ranges to the index.
Namespace
Drupal\search_api_solr\Plugin\search_api\processorCode
public function preprocessIndexItems(array $items) {
foreach ($items as $item) {
/** @var \Drupal\search_api\Item\FieldInterface $field */
foreach ($item
->getFields() as $name => $field) {
if ('solr_date_range' == $field
->getType()) {
$values = [];
$required_properties = [
$item
->getDatasourceId() => [
$field
->getPropertyPath() . ':value' => 'start',
$field
->getPropertyPath() . ':end_value' => 'end',
],
];
$item_values = $this
->getFieldsHelper()
->extractItemValues([
$item,
], $required_properties);
foreach ($item_values as $key => $dates) {
$start_dates = $dates['start'];
$end_dates = $dates['end'];
for ($i = 0, $n = count($start_dates); $i < $n; $i++) {
$values[$i] = new DateRangeValue($start_dates[$i], $end_dates[$i]);
}
}
if (!empty($values)) {
$field
->setValues($values);
}
}
}
}
}