0

我有一个属于_to Account 的课程模型。

公共课程的 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
4

1 回答 1

1

如果我理解你的问题,那么你想做这样的事情:

LessonContentBlock.search(
    :load => true, 
    :page => (params[:page] || 1)
    ) do
  query { string q }
  filter :or, {:term => {:account_id => a.id}},
              {:missing => {:field => 'account_id'}}
end

我以为我知道如何解决这个问题,但我自己却很难让它发挥作用。最终在轮胎的测试套件中找到了一个很好的例子:http: //git.io/v0PGBw

于 2013-05-04T23:27:33.713 回答