I have two models, Location
and Basic
, I'm using pg_search and geocoder gem, how do I add scope to my pg_search_scope
with geocoder near
method or if there's another method to do so?
Location
model has the latitude and longitude columns.
In my controller I'm able to do this:
# this allows me to search near the Location model
@business = Location.near(params[:loc], 15)
# this searches through the pg_search_scope
@term = Basic.search(params[:q])
#I'm trying to combine @business and @term
And with Basic
model I have this:
pg_search_scope :search, :against => [:first_name, :last_name],
:associated_against => {
:services => [:service, :description]
},
:using => {
:tsearch => {:disctionary => "english" }
}
I'd like to combine both @business
and @term
into one (@search)
Is this possible?
Thanks
++++++++++++++++
So in my Basic
model:
class Basic < ActiveRecord::Base
belongs_to :location
has_many :services, as: :servicable
pg_search_scope :search, :against => [:first_name, :last_name],
:associated_against => {
:services => [:service, :description]
},
:using => {
:tsearch => {:disctionary => "english" }
}
end
So in my model, I have services that is linked with basic. So when I search a name or a service results pop out. But I'm trying to only display results near a certain location that a user inputs, thats why I have a location_id
column in my Basic
table.
This is my Location
model
class Location < ActiveRecord::Base
has_many :basics
geocoded_by :new_address
after_validation :geocode, :if => :new_address_changed?
def gmaps4rails_address
:new_address
end
def new_address_changed?
attrs = %w(street city state)
attrs.any?{|a| send "#{a}_changed?"}
end
end
So I'm trying to chain the methods. Ideally the application would search all nearby results first, and then search the terms that matches within the nearby results, then display only those that are applicable.