LUCENE-7490: SimpleQueryParser now parses '*' as MatchAllDocsQuery

This commit is contained in:
Mike McCandless 2016-10-12 13:30:22 -04:00
parent 175370f232
commit 4ae1643f66
3 changed files with 14 additions and 0 deletions

View File

@ -53,6 +53,9 @@ New Features
in postings for fast wildcard (MultiTermQuery) highlighting.
(David Smiley, Timothy Rodriguez)
* LUCENE-7490: SimpleQueryParser now parses '*' to MatchAllDocsQuery
(Lee Hinman via Mike McCandless)
Bug Fixes
* LUCENE-7472: MultiFieldQueryParser.getFieldQuery() drops queries that are

View File

@ -145,6 +145,10 @@ public class SimpleQueryParser extends QueryBuilder {
/** Parses the query text and returns parsed query */
public Query parse(String queryText) {
if ("*".equals(queryText.trim())) {
return new MatchAllDocsQuery();
}
char data[] = queryText.toCharArray();
char buffer[] = new char[data.length];

View File

@ -623,4 +623,11 @@ public class TestSimpleQueryParser extends LuceneTestCase {
parseKeyword(sb.toString(), TestUtil.nextInt(random(), 0, 1024)); // no exception
}
}
public void testStarBecomesMatchAll() throws Exception {
Query q = parse("*");
assertEquals(q, new MatchAllDocsQuery());
q = parse(" * ");
assertEquals(q, new MatchAllDocsQuery());
}
}