apache / apache/lucene

Make check of BooleanClause.Occur[] in MultiFieldQueryParser.parse less stubborn [LUCENE-2518]

Open
#3,592 1 comment 0 reactions 0 assignees View on GitHub
affects-version:2.9 affects-version:2.9.1 affects-version:2.9.2 affects-version:2.9.3 affects-version:3.0 affects-version:3.0.1 affects-version:3.0.2 legacy-jira-priority:Minor module:core/queryparser type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

Update the check in:

public static Query parse(Version matchVersion, String query, String[] fields,
BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
if (fields.length != flags.length)
throw new IllegalArgumentException("fields.length != flags.length");

To be:
if (fields.length > flags.length)

So the consumer can use one Occur array and apply fields selectively. The only danger here is with hitting a non-existent cell in flags, and this check will provide this just as well without limiting usability for such cases.

---
Migrated from [LUCENE-2518](https://issues.apache.org/jira/browse/LUCENE-2518) by Itamar Syn-Hershko, updated Nov 30 2013

Contributor guide

Open the contributing guide

Research direction

Start at MultiFieldQueryParser.parse(Version, String, String[], BooleanClause.Occur[], Analyzer), where the current fields.length != flags.length check is shown. Verify behavior for an Occur array shorter than the fields array and confirm that an array longer than the fields array remains acceptable; done means shorter arrays no longer fail this length check while missing flag access remains protected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.