[Zope3-checkins] SVN: Zope3/trunk/src/zope/index/text/ Let text index understand a query of "cat not dog" to be equivalent to

Gary Poster gary at zope.com
Wed Jul 13 14:03:37 EDT 2005


Log message for revision 33299:
  Let text index understand a query of "cat not dog" to be equivalent to
  "cat and not dog"
  

Changed:
  U   Zope3/trunk/src/zope/index/text/queryparser.py
  U   Zope3/trunk/src/zope/index/text/tests/test_queryparser.py

-=-
Modified: Zope3/trunk/src/zope/index/text/queryparser.py
===================================================================
--- Zope3/trunk/src/zope/index/text/queryparser.py	2005-07-13 16:05:07 UTC (rev 33298)
+++ Zope3/trunk/src/zope/index/text/queryparser.py	2005-07-13 18:03:37 UTC (rev 33299)
@@ -17,7 +17,7 @@
 
 Start = OrExpr
 OrExpr = AndExpr ('OR' AndExpr)*
-AndExpr = Term ('AND' NotExpr)*
+AndExpr = Term ('AND' NotExpr | 'NOT' AndExpr)*
 NotExpr = ['NOT'] Term
 Term = '(' OrExpr ')' | ATOM+
 
@@ -179,14 +179,22 @@
         if t is not None:
             L.append(t)
         Nots = []
-        while self._check(_AND):
-            t = self._parseNotExpr()
-            if t is None:
-                continue
-            if isinstance(t, parsetree.NotNode):
-                Nots.append(t)
+        while 1:
+            if self._check(_AND):
+                t = self._parseNotExpr()
+                if t is None:
+                    continue
+                if isinstance(t, parsetree.NotNode):
+                    Nots.append(t)
+                else:
+                    L.append(t)
+            elif self._check(_NOT):
+                t = self._parseTerm()
+                if t is None:
+                    continue # Only stopwords
+                Nots.append(parsetree.NotNode(t))
             else:
-                L.append(t)
+                break
         if not L:
             return None # Only stopwords
         L.extend(Nots)

Modified: Zope3/trunk/src/zope/index/text/tests/test_queryparser.py
===================================================================
--- Zope3/trunk/src/zope/index/text/tests/test_queryparser.py	2005-07-13 16:05:07 UTC (rev 33298)
+++ Zope3/trunk/src/zope/index/text/tests/test_queryparser.py	2005-07-13 18:03:37 UTC (rev 33299)
@@ -119,6 +119,10 @@
         self.expect("aa AND NOT bb",
                     AndNode([AtomNode("aa"), NotNode(AtomNode("bb"))]))
 
+    def test008(self):
+        self.expect("aa NOT bb",
+                    AndNode([AtomNode("aa"), NotNode(AtomNode("bb"))]))
+
     def test010(self):
         self.expect('"foo bar"', PhraseNode(["foo", "bar"]))
 



More information about the Zope3-Checkins mailing list