简体   繁体   中英

How to do facet group query on Apache solr

I am doing a facet query on solr.. Which gives me facets and its count for each item... But now I want to perform a group query on facets.. Which gives me count according to group...

Example

Below is the data

Item1: Nike shoes (size:8,9,10) Item2 : Reebok Shoes(size:8,9,10)

Now in this case my brand facet query returns me result as below

  • Nike:3

  • Reebok:3

The result I required is

  • Nike:1
  • Reebok:1

Regards

have you enabled group.facet=true as explained here . You need at least 3.3

http://1XX.XXX.XXX.XXX:8080/solr/autocomplete/select?q=displayterm:new&wt=json&indent=true&q.op=and&fl=displayterm&group=true&group.field=displayterm

Note : &group=true&group.field=displayterm
This response become group by displayterm

Response :

{
  "responseHeader":{
    "status":0,
    "QTime":6,
    "params":{
      "fl":"displayterm",
      "indent":"true",
      "q":"displayterm:new",
      "q.op":"and",
      "group.field":"displayterm",
      "group":"true",
      "wt":"json"}},
  "grouped":{
    "displayterm":{
      "matches":231,
      "groups":[{
          "groupValue":null,
          "doclist":{"numFound":220,"start":0,"docs":[
              {
                "displayterm":"Professional News"}]
          }},
        {
          "groupValue":"general",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"General News"}]
          }},
        {
          "groupValue":"delhi",
          "doclist":{"numFound":2,"start":0,"docs":[
              {
                "displayterm":"New Delhi"}]
          }},
        {
          "groupValue":"care",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"New Born Care Week"}]
          }},
        {
          "groupValue":"civil",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"NEW CIVIL HOSPITAL, SURAT"}]
          }},
        {
          "groupValue":"blood",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"Newlife Blood Bank"}]
          }},
        {
          "groupValue":"college",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"New Medical College Hospital"}]
          }},
        {
          "groupValue":"degree",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"Homeopathy(Degree Course) Regulation New"}]
          }},
        {
          "groupValue":"child",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"Reproductive, Maternal, Newborn, Child and Adolescent Health"}]
          }},
        {
          "groupValue":"foundation",
          "doclist":{"numFound":1,"start":0,"docs":[
              {
                "displayterm":"The new century Medical and Educational foundation malegaon, Nashik"}]
          }}]}}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM