Class: Mongoid::Contextual::GeoNear
- Inherits:
-
Object
- Object
- Mongoid::Contextual::GeoNear
- Extended by:
- Forwardable
- Includes:
- Enumerable, Command
- Defined in:
- build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb
Instance Attribute Summary
Attributes included from Command
#collection, #collection The collection to query against., #criteria, #criteria The criteria for the context.
Instance Method Summary collapse
-
#average_distance ⇒ Float | nil
Get the average distance for all documents from the point in the command.
-
#distance_multiplier(value) ⇒ GeoNear
Provide a distance multiplier to be used for each returned distance.
-
#each ⇒ Enumerator
Iterates over each of the documents in the $geoNear, excluding the extra information that was passed back from the database.
-
#empty_and_chainable? ⇒ true
Is this context’s criteria considered empty?.
-
#execute ⇒ Hash
Execute the $geoNear, returning the raw output.
-
#initialize(collection, criteria, near) ⇒ GeoNear
constructor
Initialize the new map/reduce directive.
-
#inspect ⇒ String
Get a pretty string representation of the command.
-
#max_distance(value = nil) ⇒ GeoNear | Float
Specify the maximum distance to find documents for, or get the value of the document with the furthest distance.
-
#min_distance(value) ⇒ GeoNear
Specify the minimum distance to find documents for.
-
#spherical ⇒ GeoNear
Tell the command to calculate based on spherical distances.
-
#stats ⇒ Hash
Get the stats for the command run.
-
#time ⇒ Float
Get the execution time of the command.
-
#unique(value = true) ⇒ GeoNear
Tell the command whether or not the returned results should be unique.
Methods included from Command
Constructor Details
#initialize(collection, criteria, near) ⇒ GeoNear
Initialize the new map/reduce directive.
66 67 68 69 70 71 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 66 def initialize(collection, criteria, near) @collection, @criteria = collection, criteria command[:geoNear] = collection.name.to_s command[:near] = near end |
Instance Method Details
#average_distance ⇒ Float | nil
Get the average distance for all documents from the point in the command.
20 21 22 23 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 20 def average_distance average = stats["avgDistance"] (average.nil? || average.nan?) ? nil : average end |
#distance_multiplier(value) ⇒ GeoNear
Provide a distance multiplier to be used for each returned distance.
52 53 54 55 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 52 def distance_multiplier(value) command[:distanceMultiplier] = value self end |
#each ⇒ Enumerator
Iterates over each of the documents in the $geoNear, excluding the extra information that was passed back from the database.
34 35 36 37 38 39 40 41 42 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 34 def each if block_given? documents.each do |doc| yield doc end else to_enum end end |
#empty_and_chainable? ⇒ true
Is this context’s criteria considered empty?
186 187 188 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 186 def empty_and_chainable? true end |
#execute ⇒ Hash
Execute the $geoNear, returning the raw output.
156 157 158 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 156 def execute results end |
#inspect ⇒ String
Get a pretty string representation of the command.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 79 def inspect %Q{#<Mongoid::Contextual::GeoNear selector: #{criteria.selector.inspect} class: #{criteria.klass} near: #{command[:near]} multiplier: #{command[:distanceMultiplier] || "N/A"} max: #{command[:maxDistance] || "N/A"} min: #{command[:minDistance] || "N/A"} unique: #{command[:unique].nil? ? true : command[:unique]} spherical: #{command[:spherical] || false}> } end |
#max_distance(value = nil) ⇒ GeoNear | Float
Specify the maximum distance to find documents for, or get the value of the document with the furthest distance.
104 105 106 107 108 109 110 111 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 104 def max_distance(value = nil) if value command[:maxDistance] = value self else stats["maxDistance"] end end |
#min_distance(value) ⇒ GeoNear
Specify the minimum distance to find documents for.
121 122 123 124 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 121 def min_distance(value) command[:minDistance] = value self end |
#spherical ⇒ GeoNear
Tell the command to calculate based on spherical distances.
132 133 134 135 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 132 def spherical command[:spherical] = true self end |
#stats ⇒ Hash
Get the stats for the command run.
166 167 168 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 166 def stats results["stats"] end |
#time ⇒ Float
Get the execution time of the command.
176 177 178 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 176 def time stats["time"] end |
#unique(value = true) ⇒ GeoNear
Tell the command whether or not the returned results should be unique.
145 146 147 148 |
# File 'build/mongoid-8.1/lib/mongoid/contextual/geo_near.rb', line 145 def unique(value = true) command[:unique] = value self end |