Why Not AND, OR, And NOT?
BooleanQuery: Great Class, Bad Name
Please read full article from Why Not AND, OR, And NOT?
BooleanQuery: Great Class, Bad Name
The BooleanQuery class is probably one of the most misleading class names in the entire Lucene code base because it doesn’t model simple boolean logic query operations at all. The basic function of a BooleanQuery is:
- A BooleanQuery consists of one or more BooleanClauses, each of which contains two pieces of information:
- A nested Query
- An Occur flag, which has one of three values
MUST
– indicating that documents must match this nested Query in order for the document to match the BooleanQuery, and the score from this subquery should contribute to the score for the BooleanQueryMUST_NOT
– indicating that documents which match this nested Query are prohibited from matching the BooleanQuerySHOULD
– indicating that documents which match this nested Query should have their score from the nested query contribute to the score from the BooleanQuery, but documents can be a match for the BooleanQuery even if they do not match the nested query
- If a BooleanQuery contains no
MUST
BooleanClauses, then a document is only considered a match against the BooleanQuery if one or more of theSHOULD
BooleanClauses is a match. - The final score of a document which matches a BooleanQuery is based on the sum of the scores from all the matching
MUST
andSHOULD
BooleanClauses, multiplied by a “coord factor” based on the ratio of the number of matching BooleanClauses to the total number of BooleanClauses in the BooleanQuery.
Query Parser: Prefix Operators
In the Lucene QueryParser (and all of the other parsers that are based on it, like DisMax and EDisMax) the “prefix” operators “+” and “-” map directly to the Occur.MUST and Occur.MUST_NOT flags, while theabsence of a prefix maps to the Occur.SHOULD flag by default.
Please note how import it is to use parentheses to combine multiple operators in order in order to generate queries that correctly model boolean logic.Please read full article from Why Not AND, OR, And NOT?
No comments:
Post a Comment