[Zope-CVS] CVS: Products/ZCTextIndex - QueryParser.py:1.1.2.9

Guido van Rossum guido@python.org
Fri, 3 May 2002 12:58:08 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	QueryParser.py 
Log Message:
Make terms() a method of parse tree nodes.

=== Products/ZCTextIndex/QueryParser.py 1.1.2.8 => 1.1.2.9 ===
         return "%s(%r)" % (self.__class__.__name__, self.getValue())
 
+    def terms(self):
+        return reduce(operator.add, [v.terms() for v in self.getValue()])
+
 class NotNode(ParseTreeNode):
 
     _nodeType = "NOT"
 
+    def terms(self):
+        return []
+
 class AndNode(ParseTreeNode):
 
     _nodeType = "AND"
@@ -162,13 +168,5 @@
 
     _nodeType = "ATOM"
 
-def terms(node):
-    """Return all the ATOM nodes in a parse tree node."""
-    # XXX This is used in the test suite to find the non-NOT terms,
-    # which works only because the test queries don't have NOT terms.
-    # We'll need a more general mechanism to extra the terms if
-    # query_weight is factored into the scoring.
-    if isinstance(node, AtomNode):
-        return [node.getValue()]
-    else:
-        return reduce(operator.add, [terms(v) for v in node.getValue()])
+    def terms(self):
+        return [self.getValue()]