具有多个过滤器的 Sunspot Solr 面

发布于 2024-10-21 04:59:04 字数 427 浏览 0 评论 0原文

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

我尝试在搜索中执行此操作:

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


facet_search.facet(:attribute1, :attribute2)

通过此操作,我不断获得 nil 值,并且我确信 attribute1 和 attribute2 处存在具有相似值的记录。

假设有两条记录的 attribute1 值为“orange”。这两条记录的 attribute2 值为“eagles”。

太阳黑子中是否有一个功能可以用来根据两列对记录进行分组,我该如何做?

感谢您提前的帮助。

In sunspot solr we could group records with similar attributes via facets. But is it possible to do a facet filter from two attributes?

I tried doing this on my search:

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


facet_search.facet(:attribute1, :attribute2)

With this I keep getting nil values and I am sure that there are records with similar values at attribute1 and attribute2.

Let's say that there are two records that have values at attribute1 as "orange". And those two records have values at attribute2 as "eagles".

Is there a feature in sunspot that I could use to group records based on two columns and how do I do it?

Thanks for the help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初心未许 2024-10-28 04:59:04

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

从您的问题来看,我认为您想要按 attribute1 中的某些值和 attribute2 中的某些值进行过滤。为此,您的搜索看起来更像是:

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

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

Do you really mean you want to filter? Faceting just brings back the top n number of unique values for that attribute. So if attribute1 contained colors, you would get back orange, red, blue, etc. Any unique color that matched your current search. Faceting alone does not filter your search results.

From your question, I think you are wanting to filter by some value in attribute1 AND some value in attribute2. To do this, your search would look more like:

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

You may still include the facet :attribute1 if you wanted to get unique values for attribute1 to display in your UI or something. Just note that declaring :attribute1 as a facet does not impose a filter on the search.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文