eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\MapLocationDistanceRange::getCondition PHP Method

getCondition() protected method

Returns nested condition common for filter and query contexts.
protected getCondition ( eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion ) : array
$criterion eZ\Publish\API\Repository\Values\Content\Query\Criterion
return array
    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;
    }