[Xapian-discuss] QueryParser question

Olly Betts
Wed, 09 Sep 2009 04:00:10 -0000

On Mon, Sep 07, 2009 at 07:50:14PM -0400, Rich Lane
wrote:
> I'm using Xapian to index emails for the Sup mail client project. One
of
> our users reported that searching for messages with a query like
> "label:foo label:starred" resulted in the union of all messages
with the
> labels 'foo' and 'starred', not the intersection. This was
surprising
> because the default_op in our QueryParser instance is set to OP_AND, so
> combining a label and another field in a query would result in the
> intersection.

The "default_op" is used for the probabilistic elements of the query,
but the current documentation comment doesn't convey that at all well:

    Set the default boolean operator.

I'll replace it with something better.

> I found http://trac.xapian.org/ticket/157 which explains
> this behavior.

Yes.  This probably should be controllable on a per-prefix basis.  In
cases where each document can only have a single attribute from a set
(like "hostname" or "mime type") then the current behaviour
is great
(and AND makes no sense as no document could match) but if each document
can have multiple attributes from the set then it's possible that AND is
a better default (as in your example).

> Is there a simple way to work around this (besides requiring users to
> explicitly type 'AND')?

I'm afraid I don't see one.

Cheers,
    Olly