MultiFieldQueryParser doesn't process search strings containing field references correctly when BooleanClause.Occur.MUST_NOT is used [LUCENE-993]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
Below, and attached, is a complete java program illustrating this bug.
In this program,I have an "allowed" field and a "restricted" field. The user is not permitted to search the "restricted" field. However, if the user provides the search string "allowed:value", then the MultiFieldQueryParser returns "allowed:valu -allowed:valu", which has the effect of finding nothing.
In the case the user provides a search string containing field references, I would expect the parser to use the field and occur arrays as constraints. In other words, if a the user mentions a field that has an occur of MUST_NOT, then that field should be elided from the search. At the end of parsing, there must be at least one search term, and all MUST fields must be present.
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.analysis.snowball.SnowballAnalyzer;
public class MultiFieldQueryParserBug {
public static void main(String[] argv) {
try
{
System.out.println(MultiFieldQueryParser.parse("allowed:value",
new String[]{"allowed", "restricted"},
new BooleanClause.Occur[]{BooleanClause.Occur.SHOULD, BooleanClause.Occur.MUST_NOT},
new SnowballAnalyzer("English")));
// Output is:
// allowed:valu -allowed:valu
}
catch (ParseException e)
{
e.printStackTrace(); // generated
}
}
}
---
Migrated from [LUCENE-993](https://issues.apache.org/jira/browse/LUCENE-993) by Anthony Yeracaris, updated Nov 30 2013
Attachments: [MultiFieldQueryParserBug.java](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-993/MultiFieldQueryParserBug.java)
Contributor guide
Research direction
Start with the attached MultiFieldQueryParserBug.java program and the MultiFieldQueryParser.parse entry point; run the example to reproduce the output. Compare the result with the stated expectation for field references and MUST_NOT, then add or update coverage so the parser omits restricted referenced fields while retaining valid search terms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100