mirror of https://github.com/apache/lucene.git
LUCENE-6298: SimpleQueryParser returns empty query rather than null for empty query
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63a6080c82
commit
ec843c6e0a
|
@ -186,6 +186,9 @@ Changes in Runtime Behavior
|
|||
* LUCENE-6255: PhraseQuery now ignores leading holes and requires that
|
||||
positions are positive and added in order. (Adrien Grand)
|
||||
|
||||
* LUCENE-6298: SimpleQueryParser returns an empty query rather than
|
||||
null, if e.g. the terms were all stopwords. (Lee Hinman via Robert Muir)
|
||||
|
||||
======================= Lucene 5.0.0 =======================
|
||||
|
||||
New Features
|
||||
|
|
|
@ -141,14 +141,18 @@ public class SimpleQueryParser extends QueryBuilder {
|
|||
this.flags = flags;
|
||||
}
|
||||
|
||||
/** Parses the query text and returns parsed query (or null if empty) */
|
||||
/** Parses the query text and returns parsed query */
|
||||
public Query parse(String queryText) {
|
||||
char data[] = queryText.toCharArray();
|
||||
char buffer[] = new char[data.length];
|
||||
|
||||
State state = new State(data, buffer, 0, data.length);
|
||||
parseSubQuery(state);
|
||||
return state.top;
|
||||
if (state.top == null) {
|
||||
return new BooleanQuery();
|
||||
} else {
|
||||
return state.top;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSubQuery(State state) {
|
||||
|
|
|
@ -273,17 +273,19 @@ public class TestSimpleQueryParser extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testGarbageEmpty() throws Exception {
|
||||
assertNull(parse(""));
|
||||
assertNull(parse(" "));
|
||||
assertNull(parse(" "));
|
||||
assertNull(parse("\\ "));
|
||||
assertNull(parse("\\ \\ "));
|
||||
assertNull(parse("\"\""));
|
||||
assertNull(parse("\" \""));
|
||||
assertNull(parse("\" \"|\" \""));
|
||||
assertNull(parse("(\" \"|\" \")"));
|
||||
assertNull(parse("\" \" \" \""));
|
||||
assertNull(parse("(\" \" \" \")"));
|
||||
BooleanQuery expected = new BooleanQuery();
|
||||
|
||||
assertEquals(expected, parse(""));
|
||||
assertEquals(expected, parse(" "));
|
||||
assertEquals(expected, parse(" "));
|
||||
assertEquals(expected, parse("\\ "));
|
||||
assertEquals(expected, parse("\\ \\ "));
|
||||
assertEquals(expected, parse("\"\""));
|
||||
assertEquals(expected, parse("\" \""));
|
||||
assertEquals(expected, parse("\" \"|\" \""));
|
||||
assertEquals(expected, parse("(\" \"|\" \")"));
|
||||
assertEquals(expected, parse("\" \" \" \""));
|
||||
assertEquals(expected, parse("(\" \" \" \")"));
|
||||
}
|
||||
|
||||
public void testGarbageAND() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue