【问题标题】:Sunspot Solr facet with multiple filters带有多个过滤器的 Sunspot Solr 刻面
【发布时间】:2011-07-10 09:12:06
【问题描述】:

在 sunspot solr 中,我们可以通过 facets 对具有相似属性的记录进行分组。但是是否可以从两个属性中进行构面过滤?

我尝试在搜索中这样做:

facet_search = User.search do
  facet :attribute1, :attribute2
end


facet_search.facet(:attribute1, :attribute2)

有了这个,我不断得到 nil 值,并且我确信在属性 1 和属性 2 有具有相似值的记录。

假设有两条记录的属性 1 的值为“橙色”。这两条记录在属性 2 处的值为“eagles”。

我可以使用 sunspot 中的一项功能来根据两列对记录进行分组吗?我该怎么做?

提前感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails full-text-search solr sunspot-rails


    【解决方案1】:

    您真的是要过滤吗?分面只是带回了该属性的前 n 个唯一值。因此,如果 attribute1 包含颜色,您将返回橙色、红色、蓝色等。任何与您当前搜索匹配的唯一颜色。仅分面不会过滤您的搜索结果。

    根据您的问题,我认为您希望通过属性 1 中的某个值和属性 2 中的某个值进行过滤。为此,您的搜索看起来更像:

    facet_search = User.search do
      # Filter my results...
      with(:attribute1).equal_to("orange")
      with(:attribute2).equal_to("eagle")
    end
    

    如果您想获取属性 1 的唯一值以显示在您的 UI 或其他内容中,您仍然可以包含 facet :attribute1。请注意,将 :attribute1 声明为构面不会对搜索施加过滤器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多