org.springframework.data.mongodb.core.query

Class NearQuery



  • public final class NearQuery
    extends Object
    Builder class to build near-queries.
    Author:
    Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch
    • Method Detail

      • near

        public static NearQuery near(double x,
                                     double y)
        Creates a new NearQuery starting near the given coordinates.
        Parameters:
        x -
        y -
        Returns:
      • near

        public static NearQuery near(double x,
                                     double y,
                                     Metric metric)
        Creates a new NearQuery starting at the given coordinates using the given Metric to adapt given values to further configuration. E.g. setting a maxDistance(double) will be interpreted as a value of the initially set Metric.
        Parameters:
        x -
        y -
        metric - must not be null.
        Returns:
      • near

        public static NearQuery near(Point point)
        Creates a new NearQuery starting at the given Point.
        Parameters:
        point - must not be null.
        Returns:
      • near

        public static NearQuery near(Point point,
                                     Metric metric)
        Creates a NearQuery starting near the given Point using the given Metric to adapt given values to further configuration. E.g. setting a maxDistance(double) will be interpreted as a value of the initially set Metric.
        Parameters:
        point - must not be null.
        metric - must not be null.
        Returns:
      • getMetric

        public Metric getMetric()
        Returns the Metric underlying the actual query. If no metric was set explicitly Metrics.NEUTRAL will be returned.
        Returns:
        will never be null.
      • num

        public NearQuery num(long num)
        Configures the maximum number of results to return.
        Parameters:
        num -
        Returns:
      • skip

        public NearQuery skip(long skip)
        Configures the number of results to skip.
        Parameters:
        skip -
        Returns:
      • with

        public NearQuery with(Pageable pageable)
        Configures the Pageable to use.
        Parameters:
        pageable - must not be null
        Returns:
      • maxDistance

        public NearQuery maxDistance(double maxDistance)
        Sets the max distance results shall have from the configured origin. If a Metric was set before the given value will be interpreted as being a value in that metric. E.g.
         NearQuery query = near(10.0, 20.0, Metrics.KILOMETERS).maxDistance(150);
         
        Will set the maximum distance to 150 kilometers.
        Parameters:
        maxDistance -
        Returns:
      • maxDistance

        public NearQuery maxDistance(double maxDistance,
                                     Metric metric)
        Sets the maximum distance supplied in a given metric. Will normalize the distance but not reconfigure the query's result Metric if one was configured before.
        Parameters:
        maxDistance -
        metric - must not be null.
        Returns:
      • minDistance

        public NearQuery minDistance(double minDistance)
        Sets the minimum distance results shall have from the configured origin. If a Metric was set before the given value will be interpreted as being a value in that metric. E.g.
         NearQuery query = near(10.0, 20.0, Metrics.KILOMETERS).minDistance(150);
         
        Will set the minimum distance to 150 kilometers.
        Parameters:
        minDistance -
        Returns:
        Since:
        1.7
      • minDistance

        public NearQuery minDistance(double minDistance,
                                     Metric metric)
        Sets the minimum distance supplied in a given metric. Will normalize the distance but not reconfigure the query's result Metric if one was configured before.
        Parameters:
        minDistance -
        metric - must not be null.
        Returns:
        Since:
        1.7
      • minDistance

        public NearQuery minDistance(Distance distance)
        Sets the minimum distance to the given Distance. Will set the returned Metric to be the one of the given Distance if no Metric was set before.
        Parameters:
        distance - must not be null.
        Returns:
        Since:
        1.7
      • distanceMultiplier

        public NearQuery distanceMultiplier(double distanceMultiplier)
        Configures a CustomMetric with the given multiplier.
        Parameters:
        distanceMultiplier -
        Returns:
      • spherical

        public NearQuery spherical(boolean spherical)
        Configures whether to return spherical values for the actual distance.
        Parameters:
        spherical -
        Returns:
      • isSpherical

        public boolean isSpherical()
        Returns whether spharical values will be returned.
        Returns:
      • query

        public NearQuery query(Query query)
        Adds an actual query to the NearQuery to restrict the objects considered for the actual near operation.
        Parameters:
        query - must not be null.
        Returns:
      • getSkip

        @Nullable
        public Long getSkip()
        Returns:
        the number of elements to skip.
      • toDocument

        public org.bson.Document toDocument()
        Returns the Document built by the NearQuery.
        Returns: