You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "mayya-sharipova (via GitHub)" <gi...@apache.org> on 2026/10/23 15:54:06 UTC
[PR] Throw TooManyClauses on intervals over-expansion [lucene]
mayya-sharipova opened a new pull request, #16899:
URL: https://github.com/apache/lucene/pull/16899
### Description
Multi-term intervals sources (`prefix`, `wildcard`, `regexp`, `fuzzyTerm`, `range` and `multiterm`) throw `IllegalStateException` when they expand to more than `maxExpansions` terms. Lucene uses exception types this way:
- `IllegalArgumentException`: invalid arguments, detected when the query is built
- `IllegalStateException`: invalid internal state
- `IndexSearcher.TooManyClauses`: a query that expands to too many terms (its javadoc names prefix, wildcard and range expansion)
Going over `maxExpansions` is not an invalid internal state. The query matched more terms than its limit allows, so the error comes from the caller's query. This PR throws `TooManyClauses` instead. Applications built on Lucene can then catch this case by type and report it as a user error, without matching on the message of a generic `IllegalStateException`. `maxExpansions` is already capped at `IndexSearcher#getMaxClauseCount`.
Intervals expand terms per segment when the scorer or matches are built, not during rewrite. So this exception reaches callers during search execution, where they can't tell it apart from a real `IllegalStateException`. For example, Elasticsearch returns HTTP 500 for an `intervals` query whose `regexp` rule matches too many terms, when it should be a 400 (elastic/elasticsearch#162297).
Changes:
- `MultiTermIntervalsSource#intervals` and `#matches` throw `IndexSearcher.TooManyClauses`. The message is the same as before. The `matches()` path now reports the pattern, not the last matched term, so both paths give the same message.
- The `@throws` javadoc on the `Intervals` factory methods is updated.
- `TestIntervals` expects the new type, and a new check covers the `matches()` path.
This changes the exception type that callers see, so it targets `main` only.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org