如何使用 sunspot 仅在选定的记录中搜索文本

How to search text only in selected records using sunspot

如何在选定记录中搜索文本,而不是在模型的所有记录中搜索?

nodes_res = Node.where(id: ids)
search = nodes_res.search { keywords "query" }

但是太阳黑子在模型的所有记录中搜索:(

我还没有测试过这个,但看起来你想要 https://github.com/sunspot/sunspot#scoping-scalar-fields

看这个例子:

# Posts with a category of 1, 3, or 5
Post.search do
  with(:category_ids, [1, 3, 5])
end

所以像这样:

Node.search do
  keywords "query"
  with(:ids, [ids])
end