eZ\Publish\Core\Search\Elasticsearch\Content\SortClauseVisitor\Field\MapLocationDistance::visit PHP Method

visit() public method

Map field value to a proper Elasticsearch representation.
public visit ( eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause ) : mixed
$sortClause eZ\Publish\API\Repository\Values\Content\Query\SortClause
return mixed
    public function visit(SortClause $sortClause)
    {
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\MapLocationTarget $target */
        $target = $sortClause->targetData;
        $fieldName = $this->getSortFieldName($sortClause, $target->typeIdentifier, $target->fieldIdentifier, $this->fieldName);
        if ($fieldName === null) {
            throw new InvalidArgumentException('$sortClause->targetData', 'No searchable fields found for the given sort clause target ' . "'{$target->fieldIdentifier}' on '{$target->typeIdentifier}'.");
        }
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\MapLocationTarget $target */
        $target = $sortClause->targetData;
        return array('_geo_distance' => array('nested_path' => 'fields_doc', 'nested_filter' => array('term' => $this->getNestedFilterTerm(null)), 'order' => $this->getDirection($sortClause), "fields_doc.{$fieldName}" => array('lat' => $target->latitude, 'lon' => $target->longitude), 'unit' => 'km'));
    }