class Sunspot::Query::Geo
Constants
- DEFAULT_PRECISION
- DEFAULT_PRECISION_FACTOR
- MAX_PRECISION
Public Class Methods
new(field, lat, lng, options)
click to toggle source
# File lib/sunspot/query/geo.rb, line 14 def initialize(field, lat, lng, options) @field, @options = field, options @geohash = GeoHash.encode(lat.to_f, lng.to_f, MAX_PRECISION) end
Public Instance Methods
to_params()
click to toggle source
# File lib/sunspot/query/geo.rb, line 19 def to_params { :q => to_boolean_query } end
to_subquery()
click to toggle source
# File lib/sunspot/query/geo.rb, line 23 def to_subquery { :q => "(#{to_boolean_query})" } end
Private Instance Methods
boost()
click to toggle source
# File lib/sunspot/query/geo.rb, line 48 def boost @options[:boost] || 1.0 end
precision()
click to toggle source
# File lib/sunspot/query/geo.rb, line 40 def precision @options[:precision] || DEFAULT_PRECISION end
precision_factor()
click to toggle source
# File lib/sunspot/query/geo.rb, line 44 def precision_factor @options[:precision_factor] || DEFAULT_PRECISION_FACTOR end
to_boolean_query()
click to toggle source
# File lib/sunspot/query/geo.rb, line 29 def to_boolean_query queries = [] MAX_PRECISION.downto(precision) do |i| star = i == MAX_PRECISION ? '' : '*' precision_boost = Util.format_float( boost * precision_factor ** (i-MAX_PRECISION).to_f, 3) queries << "#{@field.indexed_name}:#{@geohash[0, i]}#{star}^#{precision_boost}" end queries.join(' OR ') end