Excluding a facet's constraint to exclude a facet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Excluding a facet's constraint to exclude a facet

Dan Davis-2
Summary - when constraining a search using filter query, how can I exclude
the constraint for a particular facet?

Detail - Suppose I have the following facet results for a query "q=*
mainquery*":

<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="foo">
<int name="A">491</int>
<int name="B">111</int>
<int name="C">103</int>
...
</lst>
...

I understand from
http://people.apache.org/~hossman/apachecon2010/facets/and Wiki
documentation that I can limit results to category "A" as follows:

fq={!raw f=foo}A

But I cannot seem to (Solr 3.6.1) exclude that way:

fq={!raw f=foo}-A

And the simpler test (with edismax) doesn't work either:

fq=foo:A        # works
fq=foo:-A       # doesn't work

Do I need to be using facet.method=enum to get this to work?   What else
could be the problem here?
Reply | Threaded
Open this post in threaded view
|

Re: Excluding a facet's constraint to exclude a facet

Chris Hostetter-3

: documentation that I can limit results to category "A" as follows:
:
: fq={!raw f=foo}A
:
: But I cannot seem to (Solr 3.6.1) exclude that way:
:
: fq={!raw f=foo}-A

with the raw" qparser, there is no markup syntax at all -- so it's
interpreting the "-" as part of the literal term value you are trying to
query for.

: And the simpler test (with edismax) doesn't work either:
:
: fq=foo:A        # works
: fq=foo:-A       # doesn't work

likewise: in the lucene/dismax/edismax parsers operatores (like "-" and
"+") need to come before the field you are querying on...

   fq=-foo:A
or fq={!edismax}-foo:A


If you upgrade to a more current 4.x version of Solr, then the
default (lucene) parser in solr has been updated to recognize
nested parser syntax (ie: "{!parser}input") as inline clauses, so you can
use something like this...

   fq=-{!raw f=foo}A

...which results in the (default) lucene parser recognizing the "-"
operator should be applied to a nested clause which is generated by asking
the "raw" parser to use the local param "f=foo" when parsing the input "A"

One thing to watch out for however is whitespace -- if you have a query
like this...

   fq=-{!raw f=foo}AAA BBB

...then the (default) lucene parser gets 2 clauses: a negated clause
resulting form asking the "raw" parser to parse "AAA" and a positive
clause that hte lucene parser parses itself, using the default search
field to look for "BBB".

You would nee to use the "v" local param to ensure that the entire string
gets parsed by the raw parser, either...

   fq=-{!raw f=foo v='AAA BBB'}
or fq=-{!raw f=foo v=$my_foo_fq}&my_foo_fq=AAA BBB




-Hoss