DateRange.php in Search API Solr 4.x
File
src/Plugin/search_api/processor/DateRange.php
View source
<?php
namespace Drupal\search_api_solr\Plugin\search_api\processor;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api_solr\Plugin\search_api\data_type\value\DateRangeValue;
class DateRange extends ProcessorPluginBase {
public function preprocessIndexItems(array $items) {
foreach ($items as $item) {
foreach ($item
->getFields() as $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 $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);
}
}
}
}
}
}