I am using Sunspot for searching and using Geocoder for addresses and then for calculating distances, Geokit-rails3.
class Product < ActiveRecord::Base
belongs_to :store
searchable do
text :name
end
end
class Store < ActiveRecord::Base
acts_as_mappable
geocoded_by :address, :latitude => :lat, :longitude => :lng
attr_accessible :lat, :lng, :address
has_many :products
end
Question
What I want when typing in a product to search for is also the ability to type an address inside of another field to search for products in that given area with a 30 mile radius.
This is my controller which allows me to search for Products:
class SearchController < ApplicationController
def index
@search = Product.search do |q|
q.fulltext params[:search]
end
@products = @search.results
end
end
So I believe the form would look something like this after I am done:
<%= form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search]" %>
<%= submit_tag "Search", :name => nil %>
<p> Search Near: </p>
<%= label_tag :location, "Search nearby an Address" %>
<%= text_field_tag :location, params[:location] %>
<% end %>
I am thinking :location
would serve as a virtual attribute for the Stores :address
in order for the field to be mapped correctly but this is all speculation.
How do I set this all up in order to achieve the specific scenario?