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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to