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 Marc SCHNEIDER <ma...@gmail.com> on 2012/01/04 13:45:43 UTC

Merging results of facet fields

Hello,

I have two fields 'product' and 'tag'.
Executing this query q=*:*&facet=true&facet.field=product&facet.field=tag
gives me this result :

<lst name="facet_fields">
  <lst name="product">
     <int name="computer">16</int>
     ...
  </lst>
  <lst name="tag">
     <int name="computer">7</int>
     ...
  </lst>
</lst>

Is there a way to group the results by value ie getting <int
name="computer">23</int>, regardless of the field names?

Thanks in advance,
Marc.

Re: Merging results of facet fields

Posted by Marc SCHNEIDER <ma...@gmail.com>.
Hi Andy and Erik,

Thanks for for your answers it really helped me!

Marc.

On Wed, Jan 4, 2012 at 2:15 PM, Erik Hatcher <er...@gmail.com> wrote:

> I'd recommend what Andy said, but if all you're interested in is a single
> term combined, you can do <facet.query=product:computer OR tag:computer>
> and you'll get the "merged" count.
>
>        Erik
>
> On Jan 4, 2012, at 07:51 , Andrew Ingram wrote:
>
> > Hi Marc,
> >
> > I'd probably have another field called "keywords" (or something) that I
> copy all the values into using copyfields, then just facet (and therefore
> filter) on that field instead.
> >
> > If there were a way to do it the way you're asking (there might be, I
> don't know), there's no guarantee that the total of 23 is correct. If
> there's overlap ie a document having both product and tag values of
> "computer", the merged total should actually be less than 23.
> >
> > - Andy
> >
> > On 4 Jan 2012, at 12:45, Marc SCHNEIDER wrote:
> >
> >> Hello,
> >>
> >> I have two fields 'product' and 'tag'.
> >> Executing this query
> q=*:*&facet=true&facet.field=product&facet.field=tag
> >> gives me this result :
> >>
> >> <lst name="facet_fields">
> >> <lst name="product">
> >>    <int name="computer">16</int>
> >>    ...
> >> </lst>
> >> <lst name="tag">
> >>    <int name="computer">7</int>
> >>    ...
> >> </lst>
> >> </lst>
> >>
> >> Is there a way to group the results by value ie getting <int
> >> name="computer">23</int>, regardless of the field names?
> >>
> >> Thanks in advance,
> >> Marc.
> >
> >
>
>

Re: Merging results of facet fields

Posted by Erik Hatcher <er...@gmail.com>.
I'd recommend what Andy said, but if all you're interested in is a single term combined, you can do <facet.query=product:computer OR tag:computer> and you'll get the "merged" count.

	Erik

On Jan 4, 2012, at 07:51 , Andrew Ingram wrote:

> Hi Marc,
> 
> I'd probably have another field called "keywords" (or something) that I copy all the values into using copyfields, then just facet (and therefore filter) on that field instead.
> 
> If there were a way to do it the way you're asking (there might be, I don't know), there's no guarantee that the total of 23 is correct. If there's overlap ie a document having both product and tag values of "computer", the merged total should actually be less than 23.
> 
> - Andy
> 
> On 4 Jan 2012, at 12:45, Marc SCHNEIDER wrote:
> 
>> Hello,
>> 
>> I have two fields 'product' and 'tag'.
>> Executing this query q=*:*&facet=true&facet.field=product&facet.field=tag
>> gives me this result :
>> 
>> <lst name="facet_fields">
>> <lst name="product">
>>    <int name="computer">16</int>
>>    ...
>> </lst>
>> <lst name="tag">
>>    <int name="computer">7</int>
>>    ...
>> </lst>
>> </lst>
>> 
>> Is there a way to group the results by value ie getting <int
>> name="computer">23</int>, regardless of the field names?
>> 
>> Thanks in advance,
>> Marc.
> 
> 


Re: Merging results of facet fields

Posted by Andrew Ingram <an...@tangentlabs.co.uk>.
Hi Marc,

I'd probably have another field called "keywords" (or something) that I copy all the values into using copyfields, then just facet (and therefore filter) on that field instead.

If there were a way to do it the way you're asking (there might be, I don't know), there's no guarantee that the total of 23 is correct. If there's overlap ie a document having both product and tag values of "computer", the merged total should actually be less than 23.

- Andy

On 4 Jan 2012, at 12:45, Marc SCHNEIDER wrote:

> Hello,
> 
> I have two fields 'product' and 'tag'.
> Executing this query q=*:*&facet=true&facet.field=product&facet.field=tag
> gives me this result :
> 
> <lst name="facet_fields">
>  <lst name="product">
>     <int name="computer">16</int>
>     ...
>  </lst>
>  <lst name="tag">
>     <int name="computer">7</int>
>     ...
>  </lst>
> </lst>
> 
> Is there a way to group the results by value ie getting <int
> name="computer">23</int>, regardless of the field names?
> 
> Thanks in advance,
> Marc.