简体   繁体   English

你怎么得到耐嚼的宝石来过滤结果?

[英]How do you get the Chewy gem to filter results?

I just started on the Chewy gem, looks like a great idea, but I'm unable to get it working properly with even a super basic query. 我刚开始使用耐嚼宝石,看起来是个好主意,但即使是超级基本查询,我也无法让它正常工作。

I have indexed my Lead model as LeadsIndex. 我已将我的Lead模型编入索引为LeadsIndex。 Here I have a query that works: 在这里,我有一个有效的查询:

irb(main):068:0> LeadsIndex.filter.first
  LeadsIndex Search (8.9ms) {:body=>{}, :index=>["leads"], :type=>[]}
=> #<LeadsIndex::Lead:0x007ff76324cbf8 @attributes={"id"=>"14", "name"=>"Victoria Roob", "_score"=>1.0, "_explanation"=>nil}, 
                                       @_data={"_index"=>"leads", "_type"=>"lead", "_id"=>"14", "_score"=>1.0, "_source"=>{"name"=>"Victoria Roob"}}>

But when I try to search for that very record, it shows no results: 但是,当我尝试搜索该记录时,它没有显示任何结果:

irb(main):071:0> LeadsIndex.filter { name == "Victoria Roob" }.first
  LeadsIndex Search (7.4ms) {:body=>{:query=>{:filtered=>{:query=>{:match_all=>{}}, :filter=>{:term=>{"name"=>"Victoria Roob"}}}}}, :index=>["leads"], :type=>[]}
=> nil

Am I doing something wrong? 难道我做错了什么?

You can either match phrase: 你可以匹配短语:

LeadsIndex.query(match_phrase: {name: "Victoria Root"}).first

or else chain the queries together: 或者将查询链接在一起:

LeadsIndex.filter { name == "Victoria" }.filter { name == "Roob" }.first

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM