Spring Data MongoDB

org.springframework.data.mongodb.core.query
Class NearQuery

java.lang.Object
  extended by org.springframework.data.mongodb.core.query.NearQuery

public class NearQuery
extends Object

Builder class to build near-queries.

Author:
Oliver Gierke

Method Summary
 NearQuery distanceMultiplier(double distanceMultiplier)
          Configures a CustomMetric with the given multiplier.
 NearQuery distanceMultiplier(Metric metric)
          Deprecated. use in(Metric) instead.
 Distance getMaxDistance()
          Returns the maximum Distance.
 Metric getMetric()
          Returns the Metric underlying the actual query.
 NearQuery in(Metric metric)
          Will cause the results' distances being returned in the given metric.
 NearQuery inKilometers()
          Will cause the results' distances being returned in kilometers.
 NearQuery inMiles()
          Will cause the results' distances being returned in miles.
 boolean isSpherical()
          Returns whether spharical values will be returned.
 NearQuery maxDistance(Distance distance)
          Sets the maximum distance to the given Distance.
 NearQuery maxDistance(double maxDistance)
          Sets the max distance results shall have from the configured origin.
 NearQuery maxDistance(double maxDistance, Metric metric)
          Sets the maximum distance supplied in a given metric.
static NearQuery near(double x, double y)
          Creates a new NearQuery starting near the given coordinates.
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.
static NearQuery near(Point point)
          Creates a new NearQuery starting at the given Point.
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.
 NearQuery num(int num)
          Configures the number of results to return.
 NearQuery query(Query query)
          Adds an actual query to the NearQuery to restrict the objects considered for the actual near operation.
 NearQuery spherical(boolean spherical)
          Configures whether to return spherical values for the actual distance.
 com.mongodb.DBObject toDBObject()
          Returns the DBObject built by the NearQuery.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

near

public static NearQuery near(double x,
                             double y)
Creates a new NearQuery starting near the given coordinates.

Parameters:
i -
j -
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 -
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 -
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(int num)
Configures the number of results to return.

Parameters:
num -
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:

maxDistance

public NearQuery maxDistance(Distance distance)
Sets the maximum 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:

getMaxDistance

public Distance getMaxDistance()
Returns the maximum Distance.

Returns:

distanceMultiplier

public NearQuery distanceMultiplier(double distanceMultiplier)
Configures a CustomMetric with the given multiplier.

Parameters:
distanceMultiplier -
Returns:

distanceMultiplier

@Deprecated
public NearQuery distanceMultiplier(Metric metric)
Deprecated. use in(Metric) instead.

Configures the distance multiplier to the multiplier of the given Metric.

Parameters:
metric - must not be null.
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:

inKilometers

public NearQuery inKilometers()
Will cause the results' distances being returned in kilometers. Sets distanceMultiplier(double) and spherical(boolean) accordingly.

Returns:

inMiles

public NearQuery inMiles()
Will cause the results' distances being returned in miles. Sets distanceMultiplier(double) and spherical(boolean) accordingly.

Returns:

in

public NearQuery in(Metric metric)
Will cause the results' distances being returned in the given metric. Sets distanceMultiplier(double) accordingly as well as spherical(boolean) if the given Metric is not Metrics.NEUTRAL.

Parameters:
metric - the metric the results shall be returned in. Uses Metrics.NEUTRAL if null is passed.
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 -
Returns:

toDBObject

public com.mongodb.DBObject toDBObject()
Returns the DBObject built by the NearQuery.

Returns:

Spring Data MongoDB

Copyright © 2011-2013-2013 SpringSource. All Rights Reserved.