Skip to content

Apache Lucene open-source search software

qp accept empty string: LUCENE-1006

Yonik Seeley16342bedb9b3
diff --git a/CHANGES.txt b/CHANGES.txt
index f73ae4b1ba6..0459b79c9ef 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,4 @@
-Lucene Change Log
+Lucene Change Log
$Id$
@@ -110,6 +110,9 @@ Bug fixes
This bug was introduced with LUCENE-843. (Grant Ingersoll via
Mike McCandless)
+16. LUCENE-1006: Fixed QueryParser to accept a "" field value (zero
+ length quoted string.) (yonik)
+
New features
1. LUCENE-906: Elision filter for French.
diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jj
index 5d20264ab40..d92d656e03b 100644
--- a/src/java/org/apache/lucene/queryParser/QueryParser.jj
+++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj
@@ -888,7 +888,7 @@ PARSER_END(QueryParser)
| <COLON: ":" >
| <STAR: "*" >
| <CARAT: "^" > : Boost
-| <QUOTED: "\"" (~["\""] | "\\\"")+ "\"">
+| <QUOTED: "\"" (~["\""] | "\\\"")* "\"">
| <TERM: <_TERM_START_CHAR> (<_TERM_CHAR>)* >
| <FUZZY_SLOP: "~" ( (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? )? >
| <PREFIXTERM: ("*") | ( <_TERM_START_CHAR> (<_TERM_CHAR>)* "*" ) >
diff --git a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
index a769c59f88d..f0b2852e2e8 100644
--- a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
+++ b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
@@ -142,7 +142,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
kind = 6;
}
else if (curChar == 34)
- jjCheckNAddTwoStates(15, 17);
+ jjCheckNAddStates(0, 2);
else if (curChar == 33)
{
if (kind > 9)
@@ -152,7 +152,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
{
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
}
else if (curChar == 42)
{
@@ -175,16 +175,13 @@ private final int jjMoveNfa_3(int startState, int curPos)
kind = 9;
break;
case 14:
+ case 16:
if (curChar == 34)
- jjCheckNAddTwoStates(15, 17);
+ jjCheckNAddStates(0, 2);
break;
case 15:
if ((0xfffffffbffffffffL & l) != 0L)
- jjCheckNAddStates(5, 7);
- break;
- case 16:
- if (curChar == 34)
- jjCheckNAddStates(5, 7);
+ jjCheckNAddStates(0, 2);
break;
case 18:
if (curChar == 34 && kind > 17)
@@ -229,7 +226,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
break;
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
break;
case 29:
if ((0x7bfff8f8ffffd9ffL & l) == 0L)
@@ -276,7 +273,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
{
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
}
else if (curChar == 92)
jjCheckNAddStates(13, 15);
@@ -342,7 +339,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
jjstateSet[jjnewStateCnt++] = 11;
break;
case 15:
- jjAddStates(5, 7);
+ jjAddStates(0, 2);
break;
case 17:
if (curChar == 92)
@@ -383,7 +380,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
break;
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
break;
case 29:
if ((0x97ffffff87ffffffL & l) == 0L)
@@ -451,12 +448,12 @@ private final int jjMoveNfa_3(int startState, int curPos)
{
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
}
break;
case 15:
if (jjCanMove_0(hiByte, i1, i2, l1, l2))
- jjAddStates(5, 7);
+ jjAddStates(0, 2);
break;
case 24:
if (!jjCanMove_0(hiByte, i1, i2, l1, l2))
@@ -470,7 +467,7 @@ private final int jjMoveNfa_3(int startState, int curPos)
break;
if (kind > 18)
kind = 18;
- jjCheckNAddStates(0, 4);
+ jjCheckNAddStates(3, 7);
break;
case 29:
case 31:
@@ -955,7 +952,7 @@ private final int jjMoveNfa_2(int startState, int curPos)
}
}
static final int[] jjnextStates = {
- 29, 32, 23, 33, 30, 15, 17, 18, 20, 21, 32, 23, 33, 31, 34, 27,
+ 15, 17, 18, 29, 32, 23, 33, 30, 20, 21, 32, 23, 33, 31, 34, 27,
2, 4, 5, 0, 1,
};
private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.java
index 82c98d97122..7a7f1edd69c 100644
--- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java
+++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java
@@ -18,13 +18,8 @@ package org.apache.lucene.queryParser;
*/
import junit.framework.TestCase;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.LowerCaseTokenizer;
-import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.Token;
-import org.apache.lucene.analysis.TokenFilter;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.DateTools;
@@ -200,6 +195,9 @@ public class TestQueryParser extends TestCase {
assertQueryEquals("türm term term", new WhitespaceAnalyzer(), "türm term term");
assertQueryEquals("ümlaut", new WhitespaceAnalyzer(), "ümlaut");
+ assertQueryEquals("\"\"", new KeywordAnalyzer(), "");
+ assertQueryEquals("foo:\"\"", new KeywordAnalyzer(), "foo:");
+
assertQueryEquals("a AND b", null, "+a +b");
assertQueryEquals("(a AND b)", null, "+a +b");
assertQueryEquals("c OR (a AND b)", null, "c (+a +b)");