andgursky
andgursky

Reputation: 352

How to search text only in selected records using sunspot

How can i search text in selected records, not in all records of the model?

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

but sunspot searches in all records of the model :(

Upvotes: 0

Views: 41

Answers (1)

lacostenycoder
lacostenycoder

Reputation: 11216

I have not tested this but it looks you you want https://github.com/sunspot/sunspot#scoping-scalar-fields

See this example:

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

So something like this:

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

Upvotes: 1

Related Questions