anshumg opened a new pull request, #5394:
URL: https://github.com/apache/solr/pull/5394

   # Description
   
   A phrase query against a field indexed without positions (`omitPositions` / 
`omitTermFreqAndPositions`) fails in Lucene with an `IllegalStateException`. 
Solr surfaces that as HTTP 500 and logs a full ERROR stack trace, because the 
exception isn't a `SolrException`. Two cases behave the same way today but 
deserve different handling:
   
   1. **Explicit phrase** (`field:"foo bar"`, or a quoted phrase in edismax 
with such a field in `qf`). This is a query/schema mismatch, so it should be a 
400.
   2. **Implicit phrase boosts** (edismax `pf`/`pf2`/`pf3`). The user never 
wrote a phrase, yet one such field fails the whole otherwise-valid request. A 
boost is best-effort and should not be able to do that.
   
   # Solution
   
   - **Explicit phrases:** `SolrQueryParserBase` overrides Lucene 
`QueryBuilder`'s `analyzePhrase`, `analyzeMultiPhrase` and 
`analyzeGraphPhrase`. When the schema says the field has no positions, it 
throws a new `PhraseNotSupportedException` (a `SolrException` with 
BAD_REQUEST). The check runs only where a phrase is actually being built, so 
non-phrase queries pay nothing.
   - **Edismax explicit phrases:** edismax's `getQuery()` deliberately swallows 
exceptions for input that doesn't fit a field (e.g. text on a numeric field). 
It now rethrows `PhraseNotSupportedException` only, so that existing behavior 
is unchanged.
   - **`pf`/`pf2`/`pf3`:** `addPhraseFieldQueries` filters out phrase fields 
the schema says lack positions, once per request.
   
   Not done on purpose:
   - Lucene's `IllegalStateException` is not re-mapped to 400; it's a generic 
type, and that would risk hiding real server bugs.
   - A schema changed without reindexing can't be caught at parse time. 
Lucene's execution-time check remains the backstop there.
   
   Behavior change: an edismax request with a quoted phrase and a `qf` that 
includes a field without positions now returns 400. Before, it returned 500 at 
execution.
   
   Developed with assistance from an AI coding assistant (Claude Code); 
reviewed and tested by me.
   
   # Tests
   
   - `TestOmitPositions`: the old `testPositions` accepted either zero hits or 
an exception, so it could never fail. It is replaced by:
     - `testExplicitPhraseIsBadRequest` (Lucene parser and edismax `qf` both 
return 400).
     - `testImplicitPhraseBoostIsSkipped` (`pf`, `pf2` and `pf3` on a 
no-positions field don't fail the request; a mixed `pf` still applies to the 
field that has positions).
   - Also run: `*ExtendedDismax*`, `*TestQueryParser*`, `gradlew check -x test`.
   
   Please review the following and check all that apply:
   
   - [ ] I have reviewed the guidelines for [How to 
Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my 
code conforms to the standards described there to the best of my ability.
   


-- 
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