Monday, February 21, 2011

Solr - multifaceting syntax

I'm having a hard time constructing the URL for a query that has more than one multifacet. I'm following the sample here:

http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html

For instance, take a look at the eBay screendump, how would the URL look like if you select 'Sony' and 'LG' in the 'Brand' section and then select 'LCD' in the 'Type' section?

Assume BRAND and TYPE are defined in schema.xml.

This URL would work if you select 'Sony' and 'LG' in the 'Brand' section:

...&facet=on&facet.field={!ex=BRAND}BRAND&fq={!tag=BRAND}BRAND:Sony%20OR%20LG

But what if you need to have selections from both 'Brand' and 'Type'? I tried this but it does not give me what I want:

...&facet=on&facet.field={!ex=BRAND}BRAND&fq={!tag=BRAND}BRAND:Sony%20OR%20LG&facet.field={!ex=TYPE}TYPE&fq={!tag=TYPE}TYPE:LCD

Any help is appreciated.

From stackoverflow
  • When you specify fq twice, only documents matching both filters will be kept. It is like having one fq with AND for the conditions. Maybe it is not what you want. If you want to keep documents having one or the other filter, you will have to use only one fq and combined the condition with OR.

    UPDATE
    After re-thinking, it makes probably more sense to have an AND between the BRAND and the TYPE filters.

    Also, do not forget to specify again in which field you apply the second condition of the Brand fq:

    fq=BRAND:Sony+OR+BRAND:LG
    

    Finally, you can specify the same exclusion for both facet.field, given:

    ...&facet=on&facet.field={!ex=bt}BRAND&facet.field={!ex=bt}TYPE&fq={!tag=bt}BRAND:Sony+OR+BRAND:LG+OR+TYPE:LCD
    
    hungster : Thanks. You are right.

0 comments:

Post a Comment