From 67d206c665dd476501d696474a393d6588e7c56d Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 12 Oct 2016 13:30:22 -0400 Subject: [PATCH] LUCENE-7490: SimpleQueryParser now parses '*' as MatchAllDocsQuery --- lucene/CHANGES.txt | 3 +++ .../lucene/queryparser/simple/SimpleQueryParser.java | 4 ++++ .../lucene/queryparser/simple/TestSimpleQueryParser.java | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 1e17025b26e..5a6ce61b0a9 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -15,6 +15,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 316d97ded2d..9391c771da1 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 31fb61ab802..f7cd556c28a 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 @@ -626,4 +626,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()); + } }