On Sat, Jan 14, 2012 at 12:56 PM, Jamie Johnson <jej2...@gmail.com> wrote:
> I'm trying to figure out a way to execute a query which would allow me
> to say there were x documents over this period of time with type a, y
> documents over the same period of time with type b and z documents
> over the same period of time with type c.  I was thinking of doing
> this using range faceting where I'd execute 3 separate queries of the
> form:
>
> solr/select?q=type:a&facet.range=datefield&facet.start=NOW-1YEAR&facet.end=NOW
> solr/select?q=type:b&facet.range=datefield&facet.start=NOW-1YEAR&facet.end=NOW
> solr/select?q=type:c&facet.range=datefield&facet.start=NOW-1YEAR&facet.end=NOW
>
> ideally I'd like to do this in a single request.  Is this possible?
> I'm thinking about something like this
>
> q=*:*&fq={!tag=a}-type:(b c)&fq={!tag=b}-type:(a
> b)&fq={!tag=c}-type:(a b)&facet=on&facet.field={!ex=a
> key=a_datefield}datefield&facet.field={!ex=b
> key=b_datefield}datefield&facet.field={!ex=c
> key=c_datefield}datefield&facet.start=NOW-1YEAR&facet.end=NOW

facet.range is meant to automatically facet over many ranges - if you
really just want 3 counts (one per type) then facet.query is a much
simpler way to achieve that.

solr/select?
q=datefield:[NOW-1YEAR TO NOW]
facet.query=type:a
facet.query=type:b
facet.query=type:c

And remember to round NOW if you want better cache hits for the base
query... something like this perhaps:
q=datefield:[NOW/MINUTE-1YEAR TO NOW/MINUTE]

-Yonik
http://www.lucidimagination.com


> Should I consider trying to do this or is it better to do this some
> other way (separate queries or any other ideas?) for performance
> reasons?  Am I over complicating the issue be trying to do this in one
> shot?
>
> Any thoughts would be greatly appreciated.

Reply via email to