[Zope-CVS] CVS: Products/ZCTextIndex/tests - testQueryParser.py:

Guido van Rossum guido@python.org
Mon, 13 May 2002 00:53:04 -0400

Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv17022/tests

Modified Files:
      Tag: TextIndexDS9-branch
Log Message:
Change the query syntax to be more Google-like.

The AND, OR and NOT operators and parentheses are still recognized,
but in addition:

- a sequence of words without operators implies AND, e.g. ``foo bar''
- double-quoted text implies phrase search, e.g. ``"foo bar"''
- words connected by punctuation implies phrase search, e.g. ``foo-bar''
- a leading hyphen implies NOT, e.g. ``foo -bar''
- these can be combined, e.g. ``foo -"foo bar"'' or ``foo -foo-bar''

=== Products/ZCTextIndex/tests/testQueryParser.py => ===
                     AndNode([AtomNode("a"), NotNode(AtomNode("b"))]))
-        self.expect("foo bar", PhraseNode("foo bar"))
+        self.expect('"foo bar"', PhraseNode("foo bar"))
+        self.expect("foo bar", AndNode([AtomNode("foo"), AtomNode("bar")]))
-        self.expect("((foo bar))", PhraseNode("foo bar"))
+        self.expect('(("foo bar"))"', PhraseNode("foo bar"))
+        self.expect("((foo bar))", AndNode([AtomNode("foo"), AtomNode("bar")]))
+        self.expect('and/', AtomNode("and"))
+        self.expect("foo-bar", PhraseNode("foo bar"))
+        self.expect("foo -bar", AndNode([AtomNode("foo"),
+                                         NotNode(AtomNode("bar"))]))
+        self.expect("-foo bar", AndNode([AtomNode("bar"),
+                                         NotNode(AtomNode("foo"))]))
+        self.expect("booh -foo-bar",
+                    AndNode([AtomNode("booh"),
+                             NotNode(PhraseNode("foo bar"))]))
+        self.expect('booh -"foo bar"',
+                    AndNode([AtomNode("booh"),
+                             NotNode(PhraseNode("foo bar"))]))
     def testParseFailures(self):
@@ -88,10 +104,12 @@
         self.failure("(foo OR)")
         self.failure("(foo AND)")
         self.failure("(NOT foo)")
+        self.failure("-foo")
+        self.failure("-foo -bar")
 def test_suite():
     return makeSuite(TestQueryParser)
-if __name__=='__main__':
+if __name__=="__main__":