You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Jamie Johnson <je...@gmail.com> on 2012/01/14 18:56:11 UTC

Faceting Question

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

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.

Re: Faceting Question

Posted by Peter Sturge <pe...@gmail.com>.
Hi,

It's quite coincidental that I was just about to ask this very
question to the forum experts.
I think this is the same sort of thing Jamie was asking about. (the
only difference in my question is that the values won't be known at
query time)

Is it possible to create a request that will return *multiple* facet
ranges - 1 for each value of a given field? (ideally, up to some
facet.limit)

For example: Let's say you query: user:* AND timestamp:[yesterday TO
now], with a facet field of 'user'.
Let's now say the faceting returns a count of 50, and there are 5
different values for 'user' - let's say user1, user2, user3, user4 and
user5 (50 things happened over the last 24 hours by 5 different
users).

Is it possible, in a single query, to get back 5 facet ranges over the
24hr period - one for each user? Or, do you simply have to do the
search, and then iterate through each value returned and date facet on
that?

Pivot faceting can give results for combinations of multiple facets,
but not ranges.

Thanks,
Peter




On Sun, Jan 15, 2012 at 3:30 PM, Lee Carroll
<le...@googlemail.com> wrote:
>>  Does
>> that make more sense?
>
> Ah I see.
>
> I'm not certain but take a look at pivot faceting
>
> https://issues.apache.org/jira/browse/SOLR-792
>
> cheers lee c

Re: Faceting Question

Posted by Lee Carroll <le...@googlemail.com>.
>  Does
> that make more sense?

Ah I see.

I'm not certain but take a look at pivot faceting

https://issues.apache.org/jira/browse/SOLR-792

cheers lee c

Re: Faceting Question

Posted by Jamie Johnson <je...@gmail.com>.
I'm not sure that will give me what I want, most likely because I was
clear what I'm looking for.  I would like to take this information and
populate a chart so you could see how many documents were created over
time of a particular type.  So basically I need the range queries so I
can populate the chart (the gaps will be larger/smaller depending on
the total size of the range, say I'm looking for 100 samples).  Does
that make more sense?

On Sat, Jan 14, 2012 at 1:15 PM, Yonik Seeley
<yo...@lucidimagination.com> wrote:
> On Sat, Jan 14, 2012 at 1:12 PM, Lee Carroll
> <le...@googlemail.com> wrote:
>> if "type" is a field use field faceting with an fq
>>
>> q=datefield:[start TO end]&fq=type:(a  b c)&facet.field=type
>
> Yep, that will work too.
>
> -Yonik
> http://www.lucidimagination.com

Re: Faceting Question

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Sat, Jan 14, 2012 at 1:12 PM, Lee Carroll
<le...@googlemail.com> wrote:
> if "type" is a field use field faceting with an fq
>
> q=datefield:[start TO end]&fq=type:(a  b c)&facet.field=type

Yep, that will work too.

-Yonik
http://www.lucidimagination.com

Re: Faceting Question

Posted by Lee Carroll <le...@googlemail.com>.
if "type" is a field use field faceting with an fq

q=datefield:[start TO end]&fq=type:(a  b c)&facet.field=type



On 14 January 2012 17:56, Jamie Johnson <je...@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
>
> 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.

Re: Faceting Question

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Sat, Jan 14, 2012 at 12:56 PM, Jamie Johnson <je...@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.