具有多个过滤器的 Sunspot Solr 面
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的是想过滤吗? Faceting 只是返回该属性的前 n 个唯一值。因此,如果 attribute1 包含颜色,您将返回橙色、红色、蓝色等与当前搜索匹配的任何唯一颜色。分面本身不会过滤您的搜索结果。
从您的问题来看,我认为您想要按 attribute1 中的某些值和 attribute2 中的某些值进行过滤。为此,您的搜索看起来更像是:
如果您想获取 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:
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.