15

Let's say I want to do faceting on the combination of two fields in my doc.

For example:

Field1  Field2
A        B
C        D
A        B
A        C
C        B
C        D

Will have the facet result like

AB [2]
CD [2]
AC [1]
CB [1]

Is this possible? I mean on the fly, which means the fields are picked randomly, and therefore cannot create a copyfield during index.

BruceCui
  • 731
  • 1
  • 6
  • 11

1 Answers1

16

You can group two fields using the Pivot Facets which is available on the Solr 4.0.

You can run the following query on your index to get it.

http://localhost:8181/solr/collection1/select?q=*:*&facet=true&facet.pivot=field1,field2

Then, the result will be like :

<lst name="facet_pivot">
  <arr name="field1,field2">
    <lst>
      <str name="field">field1</str>
      <str name="value">A</str>
      <int name="count">3</int>
      <arr name="pivot">
        <lst>
          <str name="field">field2</str>
          <str name="value">B</str>
          <int name="count">2</int>
        </lst>
        <lst>
          <str name="field">field2</str>
          <str name="value">C</str>
          <int name="count">1</int>
        </lst>
      </arr>
    </lst>
    <lst>
      <str name="field">field1</str>
      <str name="value">C</str>
      <int name="count">3</int>
      <arr name="pivot">
        <lst>
          <str name="field">field2</str>
          <str name="value">D</str>
          <int name="count">2</int>
        </lst>
        <lst>
          <str name="field">field2</str>
          <str name="value">B</str>
          <int name="count">1</int>
        </lst>
      </arr>
    </lst>
  </arr>
</lst>
Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
  • This is kind of what I'm looking for. I'm sure I can get my expected final form with this result. But the thing is that my current project still uses prior to Solr4(3.5) . Are there any approaches apply to 3.5? – BruceCui Dec 13 '12 at 11:21
  • 1
    There is another approach here but i don't know if it solve your problem. At least you can try it. http://loose-bits.com/2011/09/20/pivot-facets-solr.html – Parvin Gasimzade Dec 13 '12 at 11:25