2 つのモデルがLocationあり、 pg_searchとジオコーダーBasicgemを使用しています。ジオコーダーメソッドを使用してスコープを追加するにはどうすればよいですか?pg_search_scope near
Locationモデルには緯度と経度の列があります。
私のコントローラーでは、これを行うことができます:
# 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
そしてBasicモデルで私はこれを持っています:
pg_search_scope :search, :against => [:first_name, :last_name],
:associated_against => {
:services => [:service, :description]
},
:using => {
:tsearch => {:disctionary => "english" }
}
@business両方を@term1つにまとめたいの(@search)ですが可能ですか?
ありがとう
++++++++++++++++
だから私のBasicモデルでは:
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
したがって、私のモデルでは、基本にリンクされているサービスがあります。そのため、名前またはサービスの結果を検索すると、ポップアップが表示されます。しかし、ユーザーが入力した特定の場所の近くにのみ結果を表示しようとしています。そのため、テーブルにlocation_id列があります。Basic
これは私のLocationモデルです
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
だから私はメソッドを連鎖させようとしています。理想的には、アプリケーションは最初に近くのすべての結果を検索し、次に近くの結果内で一致する用語を検索して、適用可能なものだけを表示します。