Web / Apache Lucene Interview questions
Explain the difference between BooleanQuery and BooleanClause?
A BooleanQuery is a composite query that combines other queries logically - it's how Lucene expresses "this AND that, but NOT this other thing." It doesn't do any matching on its own; it's a container.
Each BooleanClause is one entry inside that container: a sub-query paired with an Occur value that defines how it participates:
| Occur | Meaning |
| MUST | Required; contributes to score. |
| SHOULD | Optional; boosts score if present. |
| MUST_NOT | Excludes matches; no score contribution. |
| FILTER | Required, but does not affect score. |
Building a BooleanQuery is essentially assembling a list of these Clauses with a BooleanQuery.Builder, then letting Lucene evaluate the whole logical combination as a single query.
More Related questions...