是否有人使用过具有范围的模型的Searchkick?
我有一个Article
模型scope :published, ->{ where(status: "Published") }
。
所以在ArticleController
我做了以下事情:
query = params[:q].presence || "*"
@search = Article.published.search(query, operator: "or", suggest: true)
但它不起作用API documentation并保持包含所有记录
所以我做了:
query = params[:q].presence || "*"
@search = Article.search(query, where:{status: "Published"}, operator: "or", suggest: true)
也没有工作......并且什么都没回来。 不确定我做错了什么。
答案 0 :(得分:1)
我只需要将status
添加到search_data
哈希
class Article < ActiveRecord::Base
searchkick highlight: [:title], text_start: [:title], language: "spanish"
scope :draft, ->{ where(status: "Draft") }
scope :published, ->{ where(status: "Published") }
scope :scheduled, ->{ where(status: "Scheduled") }
def search_data
{
title: title,
content: content,
status: status <--------
}
end