2013-02-22 43 views
2

我仍然是Solr领域的新手。Solr分类分类/子分类

我在尝试创建一个按类别分组的查询,返回一个唯一的sub_categories列表。我的架构类似于下面的内容:

+==============================================+ 
| 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"} 
      ] 
     }, 
     ] 
    } 
    } 
} 

回答

3

假设,你正在使用Solr的4.0+,我相信facet pivoting是一个更好的方式来做到这一点。

尝试:

http://localhost:8983/solr/select?q=*:*&facet.pivot=category,sub_category&facet=true&facet.field=category&rows=0

更新:嗯,不过这不会对虽然给你独特的计数: - ?这会给你这样的事情,如果你没有问题:

+ Apparel [5] 
|--- Pants [3] 
|--- Shirts [2] 
| 
+ Sports [2] 
|--- Balls [2] 
+0

我正在测试这个。我绝对不会使用分组或分组的输出格式,所以如果facet pivoting工作,我非常乐意使用它! – 2013-02-22 17:00:47