Skip to content

Apache Lucene open-source search software

LUCENE-6857: Validate StandardQueryParser with NOT operator with-in parantheses

Dawid Weiss8b396d82ce6e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 6aec45ff109..92fa303281c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -227,6 +227,9 @@ Bug Fixes
Other
+* LUCENE-6857: Validate StandardQueryParser with NOT operator
+ with-in parantheses. (Jigar Shah via Dawid Weiss)
+
* LUCENE-6827: Use explicit capacity ArrayList instead of a LinkedList
in MultiFieldQueryNodeProcessor. (Dawid Weiss).
diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java
index ee29952882c..bb6c0a37223 100644
--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java
+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java
@@ -538,7 +538,18 @@ public class TestQPHelper extends LuceneTestCase {
assertQueryEquals("!term", null, "-term");
assertQueryEquals("NOT term", null, "-term");
}
-
+
+ public void testNegationInParentheses() throws Exception {
+ assertQueryEquals("(-a)", null, "-a");
+ assertQueryEquals("(!a)", null, "-a");
+ assertQueryEquals("(NOT a)", null, "-a");
+ assertQueryEquals("a (!b)", null, "a (-b)");
+ assertQueryEquals("+a +(!b)", null, "+a +(-b)");
+ assertQueryEquals("a AND (!b)", null, "+a +(-b)");
+ assertQueryEquals("a (NOT b)", null, "a (-b)");
+ assertQueryEquals("a AND (NOT b)", null, "+a +(-b)");
+ }
+
public void testWildcard() throws Exception {
assertQueryEquals("term*", null, "term*");
assertQueryEquals("term*^2", null, "(term*)^2.0");