Solr:如何对两个不同的字段进行分组? [英] Solr : How can I group on two different fields?
问题描述
我的架构就像:
product_id
category_id
一个类别包含产品.
在 solr 3.6 中,我根据 category_id 对结果进行分组,并且效果很好.
A category contains products.
In solr 3.6, I group results on category_id and it works well.
我刚刚添加了一个新字段:
I just added a new field:
group_id
一组包含大小或颜色不同的产品.
示例:蓝色、红色和黄色的鞋子是 3 种不同的产品,并且具有相同的 group_id.
A group contains products that vary on size or color.
Example: shoes in blue, red and yellow are 3 differents products and have the same group_id.
除了字段 category_id 的结果分组之外,我希望在我的结果中只有一个 group_id 的产品,假设 group_id 可以为 null(对于不属于组的产品).
Additionally to the result grouping on field category_id, I would like to have in my results only one product for a group_id, assuming group_id can be null (for products that aren't part of a group).
以鞋子为例,这意味着对于请求鞋子",结果中应该只有 3 个产品中的一个.
To follow the example of the shoes, it means that for the request "shoe", only one of the 3 products should be in results.
我想对 group_id 进行第二次结果分组,但我似乎不可能这样做.
I thought to do a second result grouping on group_id, but I doesn't seem possible to do that way.
有什么想法吗?
现在,我在 php 中处理结果以删除结果中已经包含 group_id 的文档.我让这个主题保持开放,以防有人发现如何在 2 个字段上分组
EDIT : For now, i process the results in php to delete documents that have a group_id that is already in the results. I leave this subject open, in case someone finds how to group on 2 fields
推荐答案
如果您的目标是根据多个分组依据"字段获得分组计数,您可以使用 pivot faceting 来实现这一点.
If your aim is to get grouping counts based on multiple "group by" fields, you can use pivot faceting to achieve this.
&facet.pivot=category_id,group_id
Solr 将在搜索结果页面之后,在 facet_pivot
元素下为您返回分组结果计数的层次结构.
Solr will give you back a hierarchy of grouped result counts, following the page of search results, under the facet_pivot
element.
这篇关于Solr:如何对两个不同的字段进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!