[Xapian-tickets] [Xapian] #790: Operators |= and &= with Xapian::Query{}
Xapian
nobody at xapian.org
Sat Jun 29 23:16:49 BST 2019
#790: Operators |= and &= with Xapian::Query{}
-------------------------+-----------------------------
Reporter: dpa-xapian | Owner: olly
Type: defect | Status: assigned
Priority: normal | Milestone: 1.4.12
Component: Library API | Version: 1.4.11
Severity: normal | Resolution:
Keywords: | Blocked By:
Blocking: | Operating System: All
-------------------------+-----------------------------
Changes (by olly):
* status: new => assigned
* component: Other => Library API
* milestone: 1.4.x => 1.4.12
Comment:
> I do expect, that Xapian::Query{} constructs an empty query, that is the
neutral element towards AND and OR operations
Long, long ago (probably 15-20 years) we tried making a default-
constructed query work in the context-sensitive way you're expecting, but
concluded it was more confusing than helpful.
Now `Xapian::Query{}` works just like `int{}` (which is `0`) in bitwise
logical operations or `bool{}` (which is `false`) in boolean logical
operations. So `Xapian::Query{}` gives you a query which matches nothing
(and `Xapian::Query::MatchNothing` is just a static instance of this).
It's easy to handle the case of accumulating onto a query with AND:
{{{
if (t.empty()) {
t = q;
} else {
t &= q;
}
}}}
(And `t.empty()` inlines to a NULL pointer test so the extra check is low
overhead.)
> q1 |= qOR → q1.get_type() will be OR and the q1 terms will be A and B
> q2 &= qAND → q2.get_type() will be AND and the q2 terms will be A and B
>
> Instead q1.get_type() == q2.get_type() == LEAF_MATCH_NOTHING and contain
no terms.
I tested with current RELEASE/1.4 branch (this code hasn't changed since
1.4.11) and I can't reproduce `q1.get_type() == LEAF_MATCH_NOTHING` -
instead I get `q1.get_type() == OP_OR` (which is what I'd expect).
The query operators do simple folding at construction time around
`Query{}`, so for `q2` the result is simplified to `Query()` rather than
giving you an `OP_AND` query, and `q1` is actually `qOR`.
The API documentation for the default `Query` constructor just says
"Default constructor." which is uselessly vague. I'll improve that for
the next release.
--
Ticket URL: <https://trac.xapian.org/ticket/790#comment:1>
Xapian <https://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list