我仍然是 Solr 领域的新手。
我正在尝试创建一个按类别分组的查询,返回一个唯一的子类别列表。我的架构看起来类似于以下内容:
+==============================================+
| id | category | sub_category | Type |
+-----+----------+--------------+--------------+
| 1 | Apparel | Pants | Suede |
| 2 | Apparel | Pants | Leather |
| 3 | Apparel | Pants | Wind Pants |
| 4 | Apparel | Shirts | Short-Sleeve |
| 5 | Apparel | Shirts | Long-Sleeve |
| 6 | Sports | Balls | Soccer Ball |
| 7 | Sports | Balls | Football |
+-----+----------+--------------+--------------+
我有兴趣获得类似于以下内容的回报,但不确定如何完成。我几乎可以到这里,但问题是我无法让 sub_category 列返回唯一值。下面的示例确实说明了不同的子类别:
{
"responseHeader": {
"status": 0,
"QTime:" 12,
},
"grouped": {
"category": {
"matches": 1,
"groups": [
{
"groupValue": "Apparel",
'docList": {
"numFound": 2,
'start': 0,
'docs': [
{"sub_category": "Pants"},
{"sub_category": "Shirts"}
]
},
{
"groupValue": "Sports",
'docList": {
"numFound": 2,
'start': 0,
'docs': [
{"sub_category": "Balls"}
]
},
]
}
}
}