lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1662567 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/queryparser/ lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/ lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/
Date Thu, 26 Feb 2015 20:54:47 GMT
Author: rmuir
Date: Thu Feb 26 20:54:45 2015
New Revision: 1662567

URL: http://svn.apache.org/r1662567
Log:
LUCENE-6298: SimpleQueryParser returns empty query rather than null for empty query

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
    lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1662567&r1=1662566&r2=1662567&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Feb 26 20:54:45 2015
@@ -154,6 +154,9 @@ Changes in Runtime Behavior
 * LUCENE-6255: PhraseQuery now ignores leading holes and requires that
   positions are positive and added in order. (Adrien Grand)
 
+* LUCENE-6298: SimpleQueryParser returns an empty query rather than
+  null, if e.g. the terms were all stopwords. (Lee Hinman via Robert Muir)
+
 ======================= Lucene 5.0.0 =======================
 
 New Features

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java?rev=1662567&r1=1662566&r2=1662567&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
Thu Feb 26 20:54:45 2015
@@ -141,14 +141,18 @@ public class SimpleQueryParser extends Q
     this.flags = flags;
   }
 
-  /** Parses the query text and returns parsed query (or null if empty) */
+  /** Parses the query text and returns parsed query */
   public Query parse(String queryText) {
     char data[] = queryText.toCharArray();
     char buffer[] = new char[data.length];
 
     State state = new State(data, buffer, 0, data.length);
     parseSubQuery(state);
-    return state.top;
+    if (state.top == null) {
+      return new BooleanQuery();
+    } else {
+      return state.top;
+    }
   }
 
   private void parseSubQuery(State state) {

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java?rev=1662567&r1=1662566&r2=1662567&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/test/org/apache/lucene/queryparser/simple/TestSimpleQueryParser.java
Thu Feb 26 20:54:45 2015
@@ -273,17 +273,19 @@ public class TestSimpleQueryParser exten
   }
 
   public void testGarbageEmpty() throws Exception {
-    assertNull(parse(""));
-    assertNull(parse("  "));
-    assertNull(parse("  "));
-    assertNull(parse("\\ "));
-    assertNull(parse("\\ \\ "));
-    assertNull(parse("\"\""));
-    assertNull(parse("\" \""));
-    assertNull(parse("\" \"|\" \""));
-    assertNull(parse("(\" \"|\" \")"));
-    assertNull(parse("\" \" \" \""));
-    assertNull(parse("(\" \" \" \")"));
+    BooleanQuery expected = new BooleanQuery();
+
+    assertEquals(expected, parse(""));
+    assertEquals(expected, parse("  "));
+    assertEquals(expected, parse("  "));
+    assertEquals(expected, parse("\\ "));
+    assertEquals(expected, parse("\\ \\ "));
+    assertEquals(expected, parse("\"\""));
+    assertEquals(expected, parse("\" \""));
+    assertEquals(expected, parse("\" \"|\" \""));
+    assertEquals(expected, parse("(\" \"|\" \")"));
+    assertEquals(expected, parse("\" \" \" \""));
+    assertEquals(expected, parse("(\" \" \" \")"));
   }
 
   public void testGarbageAND() throws Exception {



Mime
View raw message