Rails的 - 如何searchkick过滤字符串字段?

在轨,我使用searchkick宝石搜索。我需要为过滤器添加一个名为status的字符串字段。我怎样才能添加到这个插件?Rails的 - 如何searchkick过滤字符串字段?

已经我提出关于这个问题Rails - How to add more fields for filter in searchkick?

现在我用绳子场,而不是试图布尔搜索仍不能正常工作一个问题。请帮助我一样。

我添加了一个条件像where: {status: 'approved'},按照这个条件,我应该得到的只有活跃用户(不是“删除”的用户)。目前没有搜索数据显示。

searchkick word_start: [:name] 

def initialize(name, limit = User::SUGGESTION_LIMIT, page = nil)

@name = name

@limit = limit

@page = page

@per_page = limit.to_i

end

query = {

match: :word_start,

where: {status: 'approved'},

fields: [{ emails: "exact" }, "name^5"],

misspellings: { prefix_length: 2 },

load: false

}

User.search(name, query).records

我也已经加入过滤像searchkick word_start: [:name], filterable: [:status]

Server日志尝试是,

Processing by UsersController#search as JSON 

Parameters: {"query"=>"sal"}

ETHON: Libcurl initialized

ETHON: performed EASY

effective_url=http://elastic:[email protected]:9200/users-some_index-en/_search response_code=200 return_code=ok total_time=0.498938

User Search (589.3ms) curl http://14.127.18.141:9200/users-some_index-en/_search?pretty -d '{"query":{"bool":{"must":{"dis_max":{"queries":[{"match":{"emails.true":{"query":"sal","boost":10,"operator":"and","analyzer":"searchkick_autocomplete_search"}}},{"match":{"emails.true":{"query":"sal","boost":1,"operator":"and","analyzer":"searchkick_autocomplete_search","fuzziness":1,"prefix_length":2,"max_expansions":3,"fuzzy_transpositions":true}}},{"bool":{"must":{"bool":{"should":[{"match":{"name.word_start":{"query":"sal","boost":50.0,"operator":"and","analyzer":"searchkick_word_search"}}},{"match":{"name.word_start":{"query":"sal","boost":5.0,"operator":"and","analyzer":"searchkick_word_search","fuzziness":1,"prefix_length":2,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"should":{"match":{"name.analyzed":{"query":"sal","boost":50.0,"operator":"and","analyzer":"searchkick_word_search"}}}}}]}},"filter":[{"term":{"status":"approved"}}]}},"size":5,"from":0,"timeout":"11s"}'

User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]

ETHON: performed EASY effective_url=http://elastic:[email protected]:9200/entities-some_index-en/_search response_code=200 return_code=ok total_time=0.251783

回答:

更改scope :search_import根据你的病情和修改should_index?方法一样,

def should_index? 

User.search_import

end

更改后,请致电rei ndex单独的任何数据

以上是 Rails的 - 如何searchkick过滤字符串字段? 的全部内容, 来源链接: utcz.com/qa/265179.html

回到顶部