mirror of https://github.com/apache/lucene.git
fix NullPointerException when parsing phrase query with the new MFQP
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@154406 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
db2c7c98e9
commit
cf41b3d1cb
|
@ -57,6 +57,17 @@ public class MultiFieldQueryParser extends QueryParser
|
|||
this.fields = fields;
|
||||
}
|
||||
|
||||
protected Query getFieldQuery(String field, String queryText) throws ParseException {
|
||||
if (field == null) {
|
||||
Vector clauses = new Vector();
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
clauses.add(new BooleanClause(super.getFieldQuery(fields[i], queryText),
|
||||
BooleanClause.Occur.SHOULD));
|
||||
return getBooleanQuery(clauses);
|
||||
}
|
||||
return super.getFieldQuery(field, queryText);
|
||||
}
|
||||
|
||||
protected Query getFieldQuery(String field, Analyzer analyzer, String queryText)
|
||||
throws ParseException {
|
||||
if (field == null) {
|
||||
|
|
|
@ -58,6 +58,12 @@ public class TestMultiFieldQueryParser extends TestCase {
|
|||
q = mfqp.parse("[a TO c] two");
|
||||
assertEquals("(b:[a TO c] t:[a TO c]) (b:two t:two)", q.toString());
|
||||
|
||||
q = mfqp.parse("\"foo bar\"");
|
||||
assertEquals("b:\"foo bar\" t:\"foo bar\"", q.toString());
|
||||
|
||||
q = mfqp.parse("\"aa bb cc\" \"dd ee\"");
|
||||
assertEquals("(b:\"aa bb cc\" t:\"aa bb cc\") (b:\"dd ee\" t:\"dd ee\")", q.toString());
|
||||
|
||||
// make sure that terms which have a field are not touched:
|
||||
q = mfqp.parse("one f:two");
|
||||
assertEquals("(b:one t:one) f:two", q.toString());
|
||||
|
@ -66,6 +72,8 @@ public class TestMultiFieldQueryParser extends TestCase {
|
|||
mfqp.setDefaultOperator(QueryParser.AND_OPERATOR);
|
||||
q = mfqp.parse("one two");
|
||||
assertEquals("+(b:one t:one) +(b:two t:two)", q.toString());
|
||||
q = mfqp.parse("\"aa bb cc\" \"dd ee\"");
|
||||
assertEquals("+(b:\"aa bb cc\" t:\"aa bb cc\") +(b:\"dd ee\" t:\"dd ee\")", q.toString());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue