class Mongoid::Contextual::GeoNear
def apply_criteria_options
- Since: - 3.0.0
Returns:
-
(nil)- Nothing.
Other tags:
- Example: Apply the criteria options -
Other tags:
- Api: - private
def apply_criteria_options command[:query] = criteria.selector if limit = criteria.options[:limit] command[:num] = limit end end
def average_distance
- Since: - 3.1.0
Returns:
-
(Float, nil)- The average distance.
Other tags:
- Example: Get the average distance. -
def average_distance average = stats["avgDistance"] (average.nil? || average.nan?) ? nil : average end
def distance_multiplier(value)
- Since: - 3.1.0
Returns:
-
(GeoNear)- The GeoNear wrapper.
Parameters:
-
value(Integer, Float) -- The distance multiplier.
Other tags:
- Example: Provide the distance multiplier. -
def distance_multiplier(value) command[:distanceMultiplier] = value self end
def documents
- Since: - 3.0.0
Returns:
-
(Array, Cursor)- The documents.
Other tags:
- Example: Get the documents. -
Other tags:
- Api: - private
def documents results["results"].map do |attributes| doc = Factory.from_db(criteria.klass, attributes["obj"], criteria.options[:fields]) doc.attributes["geo_near_distance"] = attributes["dis"] doc end end
def each
- Since: - 3.1.0
Returns:
-
(Enumerator)- The enumerator.
Other tags:
- Example: Iterate over the results. -
def each if block_given? documents.each do |doc| yield doc end else to_enum end end
def empty_and_chainable?
- Since: - 5.1.0
Returns:
-
(true)- Always true.
Other tags:
- Example: Is this context's criteria considered empty? -
def empty_and_chainable? true end
def execute
- Since: - 3.1.0
Returns:
-
(Hash)- The raw output
Other tags:
- Example: Run the $geoNear -
def execute results end
def initialize(collection, criteria, near)
- Since: - 3.0.0
Parameters:
-
reduce(String) -- The reduce js function. -
map(String) -- The map js function. -
criteria(Criteria) -- The Mongoid criteria.
Other tags:
- Example: Initialize the new map/reduce. -
def initialize(collection, criteria, near) @collection, @criteria = collection, criteria command[:geoNear] = collection.name.to_s command[:near] = near apply_criteria_options end
def inspect
- Since: - 3.1.0
Returns:
-
(String)- The inspection string.
Other tags:
- Example: Inspect the geoNear. -
def inspect ongoid::Contextual::GeoNear ctor: #{criteria.selector.inspect} s: #{criteria.klass} : #{command[:near]} iplier: #{command[:distanceMultiplier] || "N/A"} #{command[:maxDistance] || "N/A"} #{command[:minDistance] || "N/A"} ue: #{command[:unique].nil? ? true : command[:unique]} rical: #{command[:spherical] || false}> end
def max_distance(value = nil)
- Since: - 3.1.0
Returns:
-
(GeoNear, Float)- The GeoNear command or the value.
Parameters:
-
value(Integer, Float) -- The maximum distance.
Other tags:
- Example: Get the max distance. -
Example: Set the max distance. -
def max_distance(value = nil) if value command[:maxDistance] = value self else stats["maxDistance"] end end
def min_distance(value)
- Since: - 3.1.0
Returns:
-
(GeoNear)- The GeoNear command.
Parameters:
-
value(Integer, Float) -- The minimum distance.
Other tags:
- Example: Set the min distance. -
def min_distance(value) command[:minDistance] = value self end
def results
- Since: - 3.0.0
Returns:
-
(Hash)- The results of the command.
Other tags:
- Example: Get the results. -
Other tags:
- Api: - private
def results @results ||= client.command(command).first end
def spherical
- Since: - 3.1.0
Returns:
-
(GeoNear)- The command.
Other tags:
- Example: Add the spherical flag. -
def spherical command[:spherical] = true self end
def stats
- Since: - 3.1.0
Returns:
-
(Hash)- The stats from the command run.
Other tags:
- Example: Get the stats. -
def stats results["stats"] end
def time
- Since: - 3.1.0
Returns:
-
(Float)- The execution time.
Other tags:
- Example: Get the execution time. -
def time stats["time"] end
def unique(value = true)
- Since: - 3.1.0
Returns:
-
(GeoNear)- The command.
Parameters:
-
value(true, false) -- Whether to return unique documents.
Other tags:
- Example: Set the unique flag. -
def unique(value = true) command[:unique] = value self end