user199354
user199354

Reputation: 505

Multiple Filter Queries(fq) in SOLR

I'm having my SOLR index as:

{'year':2002
'user_entries':['user1']},
{'year':2003
'user_entries':['user2']},
{'year':2002
'user_entries':['user1']},

Expected result

{facet_fields:{2002:{'user1':2}, 2003:{'user2':1}}}

I can use fq=year:2002 to extract the facets on user_entries to extract the count of entries of each user in year 2002 as

/solr/rss/select?q=:&fq=year:2002&wt=json&indent=true&facet=true&facet.query=year:2002&facet.field=user_entries

But I want to extract the user_entries of each year from: 2002 to 2010 individually without summing them all up.

Current Approach:

1. solr/rss/select?q=*:*&fq=year:2002&wt=json&indent=true&facet=true&facet.query=year:2002&facet.field=user_entries 2. solr/rss/select?q=*:*&fq=year:2003&wt=json&indent=true&facet=true&facet.query=year:2003&facet.field=user_entries...

So can I have a single multiple filter query instead of multiple queries for each year with which I can extract individual year data without summing them up as with default OR operation?

Upvotes: 2

Views: 945

Answers (1)

Michiel van Oosterhout
Michiel van Oosterhout

Reputation: 23084

If you are using Solr 4.0 or newer then you can use pivot facets:

?q=*:*
&facet=true
&facet.pivot=year,user_entries
&f.user_entries.facet.limit=3

But the response is not exactly the same as regular field facets, so you may have to change your parsing code. You will get the count for the "2002" value of the year field, and for each combination of "2002" and values of the user_entries fields (limited to 3), followed by the same for the "2003" value.

Upvotes: 2

Related Questions