Skip to content

Commit

Permalink
Add ability to tag Geofilt restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Westcott committed Dec 27, 2013
1 parent 7d87d9c commit 4589e22
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sunspot/lib/sunspot/query/geofilt.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module Sunspot
module Query
class Geofilt
include Filter
attr_reader :field

def initialize(field, lat, lon, radius, options = {})
@field, @lat, @lon, @radius, @options = field, lat, lon, radius, options
end

def to_params
def to_boolean_phrase
func = @options[:bbox] ? "bbox" : "geofilt"
"{!#{func} sfield=#{@field.indexed_name} pt=#{@lat},#{@lon} d=#{@radius}}"
end

filter = "{!#{func} sfield=#{@field.indexed_name} pt=#{@lat},#{@lon} d=#{@radius}}"
{:fq => filter}
def to_params
{:fq => to_filter_query}
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions sunspot/spec/api/query/faceting_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@
end.should raise_error(ArgumentError)
end

it 'tags and excludes a geofilt in a field facet' do
search do
post_geo = with(:coordinates_new).in_radius(32, -68, 1)
facet(:coordinates_new, :exclude => post_geo) do
row(0..10) do
with(:coordinates_new).in_radius(32, -68, 10)
end
end
end
if connection.searches.last.has_key?(:"mlt.fl")
filter_tag = get_filter_tag('_query_:"{!geofilt sfield=coordinates_new_ll pt=32,-68 d=1}"')
else
filter_tag = get_filter_tag('{!geofilt sfield=coordinates_new_ll pt=32,-68 d=1}')
end
connection.should have_last_search_with(
:"facet.query" => "{!ex=#{filter_tag}}_query_:\"{!geofilt sfield=coordinates_new_ll pt=32,-68 d=10}\""
)
end

it 'tags and excludes a scope filter in a field facet' do
search do
blog_filter = with(:blog_id, 1)
Expand Down

0 comments on commit 4589e22

Please sign in to comment.