简体   繁体   English

ElasticSearch / Tire-构面是否未通过查询过滤?

[英]ElasticSearch / Tire - Facets are not filtered by the query?

I have an ElasticSearch / Tire query that has facets attached. 我有一个附加了构面的ElasticSearch / Tire查询。 It seems the facets a using the global scope, instead of the query scope and filters. 看来,方面是使用全局范围,而不是查询范围和过滤器。

Here is my definition. 这是我的定义。 I'm not sure how to scope the it to use the filters. 我不确定如何确定其范围以使用过滤器。

 def self.facets_for(keyword_array, fasit, opts = {})
    keyword_array = [keyword_array] if keyword_array.is_a?(String)
    tire.search(per_page: opts[:per_page], page: opts[:page] ) do 
      query do 
        boolean { should { string '*' }}
      end
      filter :terms, :keyword => keyword_array

      facet "phrases" do terms :phrases, :size => 20 end if fasit.include?("phrases")
      facet "sentiment" do terms :sentiment end if fasit.include?("sentiment")
      facet "lang" do terms :lang end if fasit.include?("lang")
      facet "provider" do terms :provider end if fasit.include?("provider")

    end # tire search
  end 

Right now, this returns facets that are "global" in scope, ie they aren't filtered by the filters (or the query if there is a more sophisticated query). 现在,这将返回范围是“全局”的构面,即它们没有被过滤器(或查询(如果有更复杂的查询))过滤。

What am I missing? 我想念什么?

Facets are by default bound (restricted) by the query issued: see the Tire integration test case . 默认绑定(限制)出具的查询:看轮胎集成测试案例

Filters, on the contrary, do not restrict the facets, making "faceted navigation" possible (again, see the integration test case ). 相反,过滤器不会限制构面,从而使“构面导航”成为可能(同样,请参见集成测试用例 )。

Note that in your example, your query is effectively a match_all query, and thus cannot restrict facets. 请注意,在您的示例中,您的查询实际上是match_all查询,因此不能限制构面。


On the Ruby side of things, a safer construct for keyword_array would be: 从Ruby的角度来看,更安全的keyword_array构造应为:

keyword_array = Array(keyword_array)

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

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