我关注:Railscasts 278并拥有以下内容:
def search
if params[:search] == ''
@search_results = []
else
@search = Challenge.search do
fulltext params[:search]
end
@search_results = @search.result
end
end
模型
searchable do
text :title, :location, :boost => 5
text :location
time :created_at
string :most_participated
end
def most_participated
Participation.group('challenge_id').order('COUNT(challenge_id) DESC')
end
我的问题是,当我搜索特定内容时,我返回了所有记录。我的日志在这里提供:
开始GET" /搜索?utf8 =%E2%9C%93& search = Test"对于127.0.0.1 at 2015-05-14 21:39:15 +0100由ChallengesController处理#search as HTML参数:{" utf8" =>"✓","搜索" =>"测试"}用户负载(0.4ms ) SELECT
users
。* FROMusers
WHEREusers
。id
= 2 ORDER BYusers
。id
ASC限制1挑战加载(0.6ms)SELECTchallenges
。* FROMchallenges
呈现挑战/ search.html.erb 在布局/应用程序内(10.6ms)
更新
任何坚持这一点的人。不要ClassName.search
由于某些未知原因它不起作用。所以我做了Sunspot.search(User) do
...轨道广播已经过时了