Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr facet counts with selective exclude

Tags:

solr

facet

I'm not sure if this is possible, but I'd like to be able to control the counts returned for facets more closely than just include and exclude.

Specifically, I have an interface that allows users to filter by 'facetA' and 'facetB'. It looks a little like this

  Filter by
    - facetA:    article (20), image (6), activity (14)
    - facetB:    cats (23), dogs(12), hedgehogs(5)

The interface makes it clear that facetA is higher in the hierarchy than facetB. I'd like the facetA counts to be completely persistent, and the facetB counts to also be persistent, but to depend on the selection of facetA.

So, the interface might react to a change to facetB with:

  Filter by
    - facetA:    article (20), image (6), activity (14)
    - facetB:    cats (23), dogs(12), hedgehogs(5)

i.e. none of the counts change.

But it would react to a facetA change like this:

  Filter by
    - facetA:    article (20), image (6), activity (14)
    - facetB:    cats (15), dogs(4), hedgehogs(1)

i.e, the facetB counts change to reflect what is available after the facetA filter has been applied.

Just doing

&facet.field={!ex=dt}fieldA&facet.field={!ex=dt}fieldB

doesn't achieve what I want it to, but it is close. I find the instructions on this in the solr wiki are very vague - like I don't even know what the 'dt' stands for. Can anyone elaborate? Can I get finer control over how counts get excluded?

like image 880
Dave Avatar asked Aug 02 '11 04:08

Dave


2 Answers

Ok, I figured this out. 'dt' is a user specified tag, which is set using the {!tag=*} statement, and referenced using the {!ex=} statement.

So, the example above is fixed if I add the following to my query:

&fq={!tag=tagA}fieldA:facetASelection
&fq={!tag=tagB}fieldB:facetBSelection
&facet=true
&facet.field={!ex=tagA}fieldA
&facet.field={!ex=tagB}fieldB

This means that the selection (fq) for facetA doesn't effect the counts for facetA, and the selection (fq) of facetB doesn't effect the counts for facetB.

Sweet! I had almost resigned myself to sending multiple queries to get the info I needed.

like image 179
Dave Avatar answered Sep 22 '22 03:09

Dave


Thanks. This answer has saved me almost a day.

Basically I was following from example in http://wiki.apache.org/solr/SimpleFacetParameters i.e.

q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=on&facet.field={!ex=dt}doctype

So when I have multiple facets, I still used {!tag=dt} & {!ex=dt} on both the facets.

Note: as rightly pointed dt is user defined tag which is used on that facet. So if I use dt for both the facets, I don't get the expected response.

Instead => use 'dt1' & 'dt2' ... for multiple facets or as explained in above example use 'tagA', 'tagB'....

Thanks again for your earlier post.

like image 37
Mandar Kelkar Avatar answered Sep 21 '22 03:09

Mandar Kelkar