带范围的 Searchkick 过滤器
Searchkick filter with scope
有人用过 Searchkick 和范围模型吗?
我有一个 Article
模型 scope :published, ->{ where(status: "Published") }
。
所以在我的 ArticleController
中,我做了以下事情:
query = params[:q].presence || "*"
@search = Article.published.search(query, operator: "or", suggest: true)
但没用https://github.com/ankane/searchkick/issues/140并保留了所有记录
所以我做了:
query = params[:q].presence || "*"
@search = Article.search(query, where:{status: "Published"}, operator: "or", suggest: true)
也没有用...并且没有返回任何内容。
不确定我做错了什么。
我只需要将 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
有人用过 Searchkick 和范围模型吗?
我有一个 Article
模型 scope :published, ->{ where(status: "Published") }
。
所以在我的 ArticleController
中,我做了以下事情:
query = params[:q].presence || "*"
@search = Article.published.search(query, operator: "or", suggest: true)
但没用https://github.com/ankane/searchkick/issues/140并保留了所有记录
所以我做了:
query = params[:q].presence || "*"
@search = Article.search(query, where:{status: "Published"}, operator: "or", suggest: true)
也没有用...并且没有返回任何内容。 不确定我做错了什么。
我只需要将 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