Apache Lucene open-source search software
LUCENE-7614: ComplexPhraseQueryParser ignores quotes around single terms phrases
Mikhail Khludnev52f2a77b78fc
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 67d8ae5ccd7..b74056faf9e 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -198,6 +198,9 @@ Improvements* LUCENE-7401: Changed the way BKD trees pick the split dimension in order toensure all dimensions are indexed. (Adrien Grand)+* LUCENE-7614: Complex Phrase Query parser ignores double quotes around single token+ prefix, wildcard, range queries (Mikhail Khludnev)+Optimizations* LUCENE-7568: Optimize merging when index sorting is used but thediff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.javaindex 1a7e5e108c1..6e18960f40a 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java@@ -255,7 +255,9 @@ public class ComplexPhraseQueryParser extends QueryParser {public Query rewrite(IndexReader reader) throws IOException {final Query contents = this.contents[0];// ArrayList spanClauses = new ArrayList();- if (contents instanceof TermQuery) {+ if (contents instanceof TermQuery+ || contents instanceof MultiTermQuery+ ) {return contents;}// Build a sequence of Span clauses arranged in a SpanNear - childdiff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.javaindex 66078b0b499..28b600ba037 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java@@ -72,6 +72,12 @@ public class TestComplexPhraseQuery extends LuceneTestCase {checkBadQuery("\"jo* \"smith\" \""); // phrases inside phrases is bad}+ public void testSingleTermPhrase() throws Exception {+ checkMatches("\"joh*\" \"tom\"", "1,2,3,4");+ checkMatches("+\"j*\" +\"tom\"", "4");+ checkMatches("\"jo*\" \"[sma TO smZ]\" ", "1,2,3");+ checkMatches("+\"j*hn\" +\"sm*h\"", "1,3");+ }public void testUnOrderedProximitySearches() throws Exception {