Using non-mapped fields in prefix queries shouldn't cause NullPointerException

Fixes #2408
This commit is contained in:
Igor Motov 2012-11-14 10:17:03 -05:00 committed by Shay Banon
parent f47d62cc30
commit 120560bd0a
2 changed files with 13 additions and 1 deletions

View File

@ -109,7 +109,9 @@ public class PrefixQueryParser implements QueryParser {
}
if (query == null) {
PrefixQuery prefixQuery = new PrefixQuery(new Term(fieldName, value));
prefixQuery.setRewriteMethod(method);
if (method != null) {
prefixQuery.setRewriteMethod(method);
}
query = prefixQuery;
}
query.setBoost(boost);

View File

@ -617,6 +617,16 @@ public class SimpleIndexQueryParserTests {
assertThat((double) prefixQuery.getBoost(), closeTo(2.0, 0.01));
}
@Test
public void testPrefixQueryWithUnknownField() throws IOException {
IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(prefixQuery("unknown", "sh")).query();
assertThat(parsedQuery, instanceOf(PrefixQuery.class));
PrefixQuery prefixQuery = (PrefixQuery) parsedQuery;
assertThat(prefixQuery.getPrefix(), equalTo(new Term("unknown", "sh")));
assertThat(prefixQuery.getRewriteMethod(), notNullValue());
}
@Test
public void testWildcardQueryBuilder() throws IOException {
IndexQueryParserService queryParser = queryParser();