diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index f076be5dfee..1981c523426 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -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 diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java index a417d1b889c..6e05aec6e8c 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java @@ -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]; diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java index a8e232723c8..d70a22c5173 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java @@ -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()); + } }