Commits

Matt Chaput committed 5c67a75

Fix syntax.BinaryGroup to deal with one of its subqueries being None.
Fixes issue #371.

  • Participants
  • Parent commits 5cf3983

Comments (0)

Files changed (2)

File src/whoosh/qparser/syntax.py

 
     def query(self, parser):
         assert len(self.nodes) == 2
-        q = self.qclass(self.nodes[0].query(parser),
-                        self.nodes[1].query(parser))
+
+        qa = self.nodes[0].query(parser)
+        qb = self.nodes[1].query(parser)
+        if qa is None and qb is None:
+            q = query.NullQuery
+        elif qa is None:
+            q = qb
+        elif qb is None:
+            q = qa
+        else:
+            q = self.qclass(self.nodes[0].query(parser),
+                            self.nodes[1].query(parser))
+
         return attach(q, self)
 
 

File tests/test_parsing.py

     assert q[0] == query.Term("f", u("Dahmen"))
     assert q[1] == query.Phrase("f", [u("Besov"), u("Spaces")], boost=9)
 
+
+def test_andmaybe_none():
+    schema = fields.Schema(f=fields.TEXT, year=fields.NUMERIC)
+    qp = default.QueryParser("f", schema)
+    _ = qp.parse(u("Dahmen ANDMAYBE @year:[2000 TO]"))
+