The solr 'lucene' query parser (that's being used there, in an fq) sometimes has trouble with "pure negative" clauses in an OR.

Even though it can handle "pure negative" queries like "-type:foo", it has trouble with pure negative in an OR like you are doing. At least in 1.4.1, don't know if it's been improved in 3.1. I _think_ you may have a case it has trouble with.

This is what I do instead, to rewrite the query to mean the same thing but not give the lucene query parser trouble:

fq=( (*:* AND -type:foo) OR restriction_id:1)

"*:*" means "everything", so (*:* AND -type:foo) means the same thing as just "-type:foo", but can get around the lucene query parsers troubles.

So that might work for you.

Dismax has even WORSE problems with "pure negative", with no easy way to get around em, so switching to dismax is probably not helpful there.

On 4/25/2011 4:27 PM, Simon Wistow wrote:
I have a field 'type' that has several values. If it's type 'foo' then
it also has a field 'restriction_id'.

What I want is a filter query which says "either it's not a 'foo' or if
it is then it has the restriction '1'"

I expect two matches - one of type 'bar' and one of type 'foo'

Neither

  fq=(-type:foo OR restriction_id:1)
  fq={!dismax q.op=OR}-type:foo restriction_id:1

produce any results.

  fq=restriction_id:1

gets the 'foo' typed result.

  fq=type:bar

get the 'bar' typed result.

Either of these

   fq=type:[* TO *] OR (type:foo AND restriction_id:1)
   fq=type:(bar OR quux OR fleeg) OR restriction_id:1

do work but are very, very slow to the point of unusability (our indexes
are pretty large).

Searching round it seems like other people have experienced similar
issues and the answer has been "Lucene just doesn't work like that"

"When dealing with Lucene people are strongly encouraged to think in
terms of MUST, MUST_NOT and SHOULD (which are represented in the query
parser as the prefixes "+", "-" and the default) instead of in terms of
AND, OR, and NOT ... Lucene's Boolean Queries (and thus Lucene's
QueryParser) is not a strict Boolean Logic system, so it's best not to
try and think of it like one."

   http://wiki.apache.org/lucene-java/BooleanQuerySyntax

Am I just out of luck? Might edismax help here?

Simon







Reply via email to