java.lang.Object
org.hibernate.search.mapper.pojo.search.definition.binding.builtin.DistanceProjectionBinder
All Implemented Interfaces:
ProjectionBinder

public final class DistanceProjectionBinder extends Object implements ProjectionBinder
Binds a constructor parameter to a projection to the distance from the center to a field in the indexed document.
See Also:
  • Method Details

    • create

      public static DistanceProjectionBinder create(String parameterName)
      Creates a DistanceProjectionBinder to be passed to MethodParameterMappingStep.projection(ProjectionBinder).

      This method requires the projection constructor class to be compiled with the -parameters flag to infer the field path from the name of the constructor parameter being bound. If this compiler flag is not used, use create(String) instead and pass the field path explicitly.

      Parameters:
      parameterName - The name of the parameter representing the center point from which the distance to the field value is going to be calculated.
      Returns:
      The binder.
      See Also:
      • SearchProjectionFactory.distance(String, GeoPoint)
      • SearchProjectionFactory.withParameters(Function)
    • create

      public static DistanceProjectionBinder create(String fieldPath, String parameterName)
      Parameters:
      fieldPath - The path to the index field whose value will be extracted. When null, defaults to the name of the constructor parameter being bound, if it can be retrieved (requires the class to be compiled with the -parameters flag; otherwise a null fieldPath will lead to a failure).
      parameterName - The name of the parameter representing the center point from which the distance to the field value is going to be calculated.
      Returns:
      The binder.
      See Also:
      • SearchProjectionFactory.distance(String, GeoPoint)
      • SearchProjectionFactory.withParameters(Function)
    • unit

      public DistanceProjectionBinder unit(org.hibernate.search.engine.spatial.DistanceUnit unit)
      Parameters:
      unit - The unit of the computed distance (default is meters).
      Returns:
      this, for method chaining.
      See Also:
      • DistanceToFieldProjectionOptionsStep.unit(DistanceUnit)
    • bind

      public void bind(ProjectionBindingContext context)
      Description copied from interface: ProjectionBinder
      Binds a constructor parameter to a projection.

      The context passed in parameter provides various information about the constructor parameter being bound. Implementations are expected to take advantage of that information and to call one of the definition*(...) methods on the context to set the projection.

      Specified by:
      bind in interface ProjectionBinder
      Parameters:
      context - A context object providing information about the constructor parameter being bound, and expecting a call to one of its definition*(...) methods.