Class: Sunspot::Query::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/query/local.rb

Overview

This query component generates parameters for LocalSolr geo-radial searches. The LocalSolr API is fairly rigid, so the Local component doesn't have any options - it just takes coordinates and a radius, and generates the appropriate parameters.

Instance Method Summary collapse

Constructor Details

#initialize(coordinates, options) ⇒ Local

Returns a new instance of Local.


10
11
12
# File 'lib/sunspot/query/local.rb', line 10

def initialize(coordinates, options)
  @coordinates, @options = Util::Coordinates.new(coordinates), options
end

Instance Method Details

#to_paramsObject


14
15
16
17
18
19
20
21
22
23
# File 'lib/sunspot/query/local.rb', line 14

def to_params
  local_params = [
    [:radius, @options[:distance]],
    [:sort, @options[:sort]]
  ].map do |key,value|
    "#{key}=#{value}" if value
  end.compact.join(" ") #TODO Centralized local param builder
  query = "{!#{local_params}}#{@coordinates.lat},#{@coordinates.lng}"
  { :spatial => query }
end