[Zope-CVS] CVS: Products/ZCTextIndex - IQueryParseTree.py:1.1 IQueryParser.py:1.5 ParseTree.py:1.7 QueryParser.py:1.9

Guido van Rossum guido@python.org
Fri, 24 May 2002 12:47:56 -0400


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

Modified Files:
	IQueryParser.py ParseTree.py QueryParser.py 
Added Files:
	IQueryParseTree.py 
Log Message:
Move IQueryParseTree to a separate file, to conform to style
guidelines.  Added some conformance tests.


=== Added File Products/ZCTextIndex/IQueryParseTree.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

"""Query Parser Tree Interface."""

import Interface

class IQueryParseTree(Interface.Base):
    """Interface for parse trees returned by parseQuery()."""

    def nodeType():
        """Return the node type.

        This is one of 'AND', 'OR', 'NOT', 'ATOM', 'PHRASE' or 'GLOB'.
        """

    def getValue():
        """Return a node-type specific value.

        For node type:    Return:
        'AND'             a list of parse trees
        'OR'              a list of parse trees
        'NOT'             a parse tree
        'ATOM'            a string (representing a single search term)
        'PHRASE'          a string (representing a search phrase)
        'GLOB'            a string (representing a pattern, e.g. "foo*")
        """

    def terms():
        """Return a list of all terms in this node, excluding NOT subtrees."""

    def executeQuery(index):
        """Execute the query represented by this node against the index.

        The index argument must implement the IIndex interface.

        Return an IIBucket or IIBTree mapping document ids to scores
        (higher scores mean better results).

        May raise ParseTree.QueryError.
        """


=== Products/ZCTextIndex/IQueryParser.py 1.4 => 1.5 ===
         May raise ParseTree.ParseError.
         """
-
-class IQueryParseTree(Interface.Base):
-    """Interface for parse trees returned by parseQuery()."""
-
-    def nodeType():
-        """Return the node type.
-
-        This is one of 'AND', 'OR', 'NOT', 'ATOM', 'PHRASE' or 'GLOB'.
-        """
-
-    def getValue():
-        """Return a node-type specific value.
-
-        For node type:    Return:
-        'AND'             a list of parse trees
-        'OR'              a list of parse trees
-        'NOT'             a parse tree
-        'ATOM'            a string (representing a single search term)
-        'PHRASE'          a string (representing a search phrase)
-        'GLOB'            a string (representing a pattern, e.g. "foo*")
-        """
-
-    def terms():
-        """Return a list of all terms in this node, excluding NOT subtrees."""
-
-    def executeQuery(index):
-        """Execute the query represented by this node against the index.
-
-        The index argument must implement the IIndex interface.
-
-        Return an IIBucket or IIBTree mapping document ids to scores
-        (higher scores mean better results).
-
-        May raise ParseTree.QueryError.
-        """


=== Products/ZCTextIndex/ParseTree.py 1.6 => 1.7 ===
 from BTrees.IIBTree import difference
 
+from Products.ZCTextIndex.IQueryParseTree import IQueryParseTree
 from Products.ZCTextIndex.SetOps import mass_weightedIntersection, \
                                         mass_weightedUnion
 
@@ -26,6 +27,8 @@
     pass
 
 class ParseTreeNode:
+
+    __implements__ = IQueryParseTree
 
     _nodeType = None
 


=== Products/ZCTextIndex/QueryParser.py 1.8 => 1.9 ===
 import re
 
-import ParseTree # relative import
+from Products.ZCTextIndex.IQueryParser import IQueryParser
+from Products.ZCTextIndex import ParseTree
 
 # Create unique symbols for token types.
 _AND    = intern("AND")
@@ -93,6 +94,8 @@
 """, re.VERBOSE)
 
 class QueryParser:
+
+    __implements__ = IQueryParser
 
     # This class is not thread-safe;
     # each thread should have its own instance