1. Overview

Solr provide facility to group or cluster search result into categories that let users drill into search results by any value in any field. Solr faceting is used in many applications to give an overall idea about how the data resides in the index.

Solr pivot faceting or decision tree faceting or sub faceting used to provide more details view of index data.we can calculate sub facet of parent facet or generate tree like structure of data and display it in the application which helps us take better decision.

2. Pivot Faceting Parameters with an example

Let’s have a quick look at some of the common parameters that used in Solr field value faceting.We will use films index in examples.

2.1 facet.pivot

This parameter used to define fields to use for pivot facet. We need to specify multiple field names separated by a comma.Here we will discuss two pivot fields, three pivot fields and four pivot fields with an example.

2.2 facet.pivot.mincount

This parameter defines the minimum number of documents should match to add in results.The default value of this param is 1.

In below example, we will use our techproducts data to generate various pivot faceting.

3. Pivot Faceting on two fields example

We need to specify two fields under facet.pivot params.Solr treat first field as a parent facet and second field as a chid facet.

3.1 Query

Here we have used popularity as a parent field and cat as a child or sub facet field.

http://localhost:8080/solr/PivotFacetingExample/select?q=*:*
  &wt=json&
  facet.pivot=popularity,cat&
  facet.pivot.mincount=2&
  facet=true&
  rows=0&
  indent=true

3.1 Output

{
  "responseHeader":{
    "status":0,
    "QTime":3,
    "params":{
      "q":"*:*",
      "facet.pivot":"popularity,cat",
      "indent":"true",
      "rows":"0",
      "wt":"json",
      "facet":"true",
      "facet.pivot.mincount":"2"}},
  "response":{"numFound":32,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{},
    "facet_pivot":{
      "popularity,cat":[{
          "field":"popularity",
          "value":6,
          "count":5,
          "pivot":[{
              "field":"cat",
              "value":"electronics",
              "count":3},
            {
              "field":"cat",
              "value":"hard drive",
              "count":2}]},
        {
          "field":"popularity",
          "value":7,
          "count":4,
          "pivot":[{
              "field":"cat",
              "value":"electronics",
              "count":4},
            {
              "field":"cat",
              "value":"graphics card",
              "count":2}]},
        {
          "field":"popularity",
          "value":1,
          "count":2,
          "pivot":[{
              "field":"cat",
              "value":"connector",
              "count":2},
            {
              "field":"cat",
              "value":"electronics",
              "count":2}]},
        {
          "field":"popularity",
          "value":10,
          "count":2}]}}}

 

4. Pivot Faceting on three fields example

Solr pivot faceting supports more than two fields to generate decision tree, which is used more in real life applications.

4.1 Query

http://localhost:8080/solr/PivotFacetingExample/select?q=*:*&
  facet=true&
  facet.pivot=cat,popularity,inStock&
  facet.pivot.mincount=2&
  rows=0&
  wt=json&
  indent=true

4.2 Output

{
  "responseHeader":{
    "status":0,
    "QTime":4,
    "params":{
      "q":"*:*",
      "facet.pivot":"cat,popularity,inStock",
      "indent":"true",
      "rows":"0",
      "wt":"json",
      "facet":"true",
      "facet.pivot.mincount":"2"}},
  "response":{"numFound":32,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{},
    "facet_pivot":{
      "cat,popularity,inStock":[{
          "field":"cat",
          "value":"electronics",
          "count":12,
          "pivot":[{
              "field":"popularity",
              "value":7,
              "count":4,
              "pivot":[{
                  "field":"inStock",
                  "value":false,
                  "count":2},
                {
                  "field":"inStock",
                  "value":true,
                  "count":2}]},
            {
              "field":"popularity",
              "value":6,
              "count":3,
              "pivot":[{
                  "field":"inStock",
                  "value":true,
                  "count":3}]},
            {
              "field":"popularity",
              "value":1,
              "count":2,
              "pivot":[{
                  "field":"inStock",
                  "value":false,
                  "count":2}]}]},
        {
          "field":"cat",
          "value":"currency",
          "count":4},
        {
          "field":"cat",
          "value":"memory",
          "count":3},
        {
          "field":"cat",
          "value":"connector",
          "count":2,
          "pivot":[{
              "field":"popularity",
              "value":1,
              "count":2,
              "pivot":[{
                  "field":"inStock",
                  "value":false,
                  "count":2}]}]},
        {
          "field":"cat",
          "value":"graphics card",
          "count":2,
          "pivot":[{
              "field":"popularity",
              "value":7,
              "count":2,
              "pivot":[{
                  "field":"inStock",
                  "value":false,
                  "count":2}]}]},
        {
          "field":"cat",
          "value":"hard drive",
          "count":2,
          "pivot":[{
              "field":"popularity",
              "value":6,
              "count":2,
              "pivot":[{
                  "field":"inStock",
                  "value":true,
                  "count":2}]}]},
        {
          "field":"cat",
          "value":"search",
          "count":2},
        {
          "field":"cat",
          "value":"software",
          "count":2}]}}}

 

5. Pivot Faceting on four fields example

In some of the analytics application where users want’s deep insights in data, to meet this type of requirements we can use pivot faceting for more than three fields.It is same as pivot faceting on two or three fields but it takes more time.

5.1 Query

http://localhost:8080/solr/PivotFacetingExample/select?q=*:*&
  facet.pivot=popularity,cat,name,inStock&
  facet.pivot.mincount=2&
  facet=true&
  rows=0&
  wt=json&
  indent=true

5.1 Output

{
  "responseHeader":{
    "status":0,
    "QTime":21,
    "params":{
      "q":"*:*",
      "facet.pivot":"popularity,cat,name,inStock",
      "indent":"true",
      "rows":"0",
      "facet":"true",
      "wt":"json",
      "facet.pivot.mincount":"2"}},
  "response":{"numFound":32,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{},
    "facet_pivot":{
      "popularity,cat,name,inStock":[{
          "field":"popularity",
          "value":6,
          "count":5,
          "pivot":[{
              "field":"cat",
              "value":"electronics",
              "count":3,
              "pivot":[{
                  "field":"name",
                  "value":"drive",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]},
                {
                  "field":"name",
                  "value":"gb",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]},
                {
                  "field":"name",
                  "value":"hard",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]}]},
            {
              "field":"cat",
              "value":"hard drive",
              "count":2,
              "pivot":[{
                  "field":"name",
                  "value":"drive",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]},
                {
                  "field":"name",
                  "value":"gb",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]},
                {
                  "field":"name",
                  "value":"hard",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":true,
                      "count":2}]}]}]},
        {
          "field":"popularity",
          "value":7,
          "count":4,
          "pivot":[{
              "field":"cat",
              "value":"electronics",
              "count":4,
              "pivot":[{
                  "field":"name",
                  "value":"mb",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":false,
                      "count":2}]}]},
            {
              "field":"cat",
              "value":"graphics card",
              "count":2,
              "pivot":[{
                  "field":"name",
                  "value":"mb",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":false,
                      "count":2}]}]}]},
        {
          "field":"popularity",
          "value":1,
          "count":2,
          "pivot":[{
              "field":"cat",
              "value":"connector",
              "count":2,
              "pivot":[{
                  "field":"name",
                  "value":"ipod",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":false,
                      "count":2}]}]},
            {
              "field":"cat",
              "value":"electronics",
              "count":2,
              "pivot":[{
                  "field":"name",
                  "value":"ipod",
                  "count":2,
                  "pivot":[{
                      "field":"inStock",
                      "value":false,
                      "count":2}]}]}]},
        {
          "field":"popularity",
          "value":10,
          "count":2}]}}}

3. Conclusion

In this article we have discuss solr pivot faceting with details parameter.We have also discussed two, three and four level of pivot faceting with example.

4. References

Refer Solr Reference Guide , Solr Range Faceting Example , solr field value faceting example for more details.

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *