solr:按多值字段分组

时间:2016-01-28 14:49:00

标签: solr group-by faceted-search multivalue

我有一个solr doc结构

   [
     {
       category:{mobiles},
       name: iphone,
       store: chroma,
       discount: 10%
     },
    {
       category:{mobiles,laptops},
       name: Apple,
       store: Reliance Digitals,
       discount: 12%
     },{
       category:{electornics},
       name: Boss,
       store: chroma,
       discount: 5%
     },{
       category:{headphones,mobiles},
       name: Samsung,
       store: Universal,
       discount: 8%
     },{
       category:{headphones},
       name: HTC,
       store: Chroma,
       discount: 50%
     },
    ]

我需要带有响应的solr查询

{
  headphones: 2
  mobiles: 3
  laptops: 1
  electornics: 1
}

简单地说,我需要对多值字段进行分组计数。

请帮助我。

感谢。

1 个答案:

答案 0 :(得分:3)

试试这个:

?q=*:*&facet=true&facet.field=category

确保索引多值字段。