[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - ResultSet.py:1.1.2.1

Andreas Jung andreas@digicool.com
Tue, 15 Jan 2002 12:39:59 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv4286

Added Files:
      Tag: ajung-textindexng-branch
	ResultSet.py 
Log Message:
new class to hold results


=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/ResultSet.py ===
#############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################

__version__ = "$Id: ResultSet.py,v 1.1.2.1 2002/01/15 17:39:59 andreasjung Exp $"

from BTrees.IIBTree import IIBucket,IISet
from BTrees.OOBTree import OOSet
from BTrees.IOBTree import IOBucket
from BTrees.IIBTree import weightedIntersection,  difference
from BTrees.IIBTree import union as Iunion
from BTrees.IIBTree import intersection as Iintersection
from BTrees.OOBTree import union as Ounion
from BTrees.IOBTree import IOBTree

from TextIndexCommon import debug


class ResultSet:
    """ class to keep results for TextIndexNG queries """

    def __init__(self, mapping, words): 
        """ 'mapping' is either an IOBTree containg the mapping  
            documentId to list of positions of a wid/word in this
            document or an IISet() with a list of documentIds.

            'words' is a list of words (from the query)
        """

        # create a new IOBTree with the documentIds as keys

        if isinstance(mapping,IISet):
            self._mapping = IOBTree()

            for k in mapping:
                self._mapping[k] = IISet() 

        else:
            self._mapping   = mapping


        self._docIds    = IISet(mapping.keys())
        self._words     = OOSet(words)


        self.items   = self._mapping.items
        self.keys    = self._mapping.keys
        self.values  = self._mapping.values
        self.has_key = self._mapping.has_key


    def docIds(self):       return self._docIds
    def words(self):        return self._words

    def __str__(self):
        s = 'ResultSet([%s], %s)' % \
            (self.words(),str(self._docIds)) 

        return s

    __repr__ = __str__