2
Sunspotの検索結果をwith(:is_available, true)
でフィルタリングしたいと考えています。 これはUser
モデルで動作していますが、Itinerary
モデルでは動作しません。ネストされたモデルでSunspot検索を制限する方法は?
アプリ/コントローラ/ search_controller.rb:
class SearchController < ApplicationController
before_filter :fulltext_actions
private
def fulltext_actions
@itineraries = do_fulltext_search(Itinerary)
@users = do_fulltext_search(User)
@itineraries_size = @itineraries.size
@users_size = @users.size
end
def do_fulltext_search(model)
Sunspot.search(model) do
with(:is_available, true)
fulltext params[:search]
end.results
end
end
アプリ/モデル/ user.rb:
class User < ActiveRecord::Base
has_many :itineraries, :dependent => :destroy
searchable do
text :first_name, :boost => 3
text :last_name, :boost => 3
text :status
boolean :is_available, :using => :available?
end
def available?
!self.suspended
end
end
アプリ/モデル/ itinerary.rb:
class Itinerary < ActiveRecord::Base
belongs_to :user
searchable do
text :title, :boost => 3
text :budget
text :description
boolean :is_available, :using => :available?
end
def available?
!self.user.suspended
end
end
どれでもアイデア?
ありがとうございます!
ノーオペレーション 'inject'文で何をアップですか?そこに 'to_a'を探していますか? – outoftime
ねえ...はい。まあ、もう少し寝る必要があります... –