I am implementing a Rails 3.1 application in combination with the sunspot_rails gem (2.0.0.pre) and I am trying to scope search results based on multiple conditions, one of them using the in_radius method to filter on geographic distance to a certain point:
Sunspot.search(Post) do
any_of do
with(:location).in_radius(position[:lat], position[:lng], 50, :bbox => true)
with :expired_at, nil
end
end
The code above leads to the following error: “undefined method `in_radius’ for Sunspot::DSL::Restriction:0x007fa7e60f0790”. Outside the any_of block the in_radius method works like a charm.
Since spatial search is still a pre-release feature of sunspot, it seems that no support for scoping was implemented yet. Does anyone know a workaround for spatial scoping as part of a disjunction in sunspot?
Has been fixed with PR https://github.com/sunspot/sunspot/pull/271 You can use the latest pre-released version of this gem to get the desired functionality.