protected function getCondition(Criterion $criterion)
{
$criterion->value = (array) $criterion->value;
$start = $criterion->value[0];
$end = isset($criterion->value[1]) ? $criterion->value[1] : 63510;
// Converting kilometers to meters, which is default distance unit in Elasticsearch
$start *= 1000;
$end *= 1000;
$fieldNames = $this->getFieldNames($criterion, $criterion->target, $this->fieldTypeIdentifier, $this->fieldName);
if (empty($fieldNames)) {
throw new InvalidArgumentException('$criterion->target', "No searchable fields found for the given criterion target '{$criterion->target}'.");
}
/** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value\MapLocationValue $location */
$location = $criterion->valueData;
$range = $this->getFilterRange($criterion->operator, $start, $end);
$filters = array();
foreach ($fieldNames as $name) {
$filter = $range;
$filter["fields_doc.{$name}"] = array('lat' => $location->latitude, 'lon' => $location->longitude);
$filters[] = array('geo_distance_range' => $filter);
}
return $filters;
}