我有一个belongs_to账号的课程模型。
公共课程的account_id为零。
私人课程在account_id中有价值。
如何为出现在公共课程和私人课程中的某些搜索词编写搜索课程?
LessonContentBlock.search(
:load => true,
:page => (params[:page] || 1)
) do
query do
boolean do
should { string q }
filter :missing => { :field => 'account_id' }
should { string "account_id:#{a.id}" }
end
end
end我也尝试过这个:
LessonContentBlock.search(
:load => true,
:page => (params[:page] || 1)
) do
query { string q }
filter :missing, :field => 'account_id'
filter :term, :account_id => a.id
end发布于 2013-05-05 07:27:34
如果我理解你的问题,那么你应该这样做:
LessonContentBlock.search(
:load => true,
:page => (params[:page] || 1)
) do
query { string q }
filter :or, {:term => {:account_id => a.id}},
{:missing => {:field => 'account_id'}}
end我认为我知道如何解决这个问题,但我自己却很难让它正常工作。最终在Tire的测试套件中找到了一个很好的例子:http://git.io/v0PGBw。
https://stackoverflow.com/questions/16377976
复制相似问题