[Zope3-checkins] CVS: Zope3/src/zope/fieldindex - fieldindex.py:1.5 ifieldindex.py:1.3

Andreas Jung andreas@andreas-jung.com
Thu, 27 Mar 2003 05:16:56 -0500


Update of /cvs-repository/Zope3/src/zope/fieldindex
In directory cvs.zope.org:/tmp/cvs-serv18196

Modified Files:
	fieldindex.py ifieldindex.py 
Log Message:
- added support for range searches
- code cleanup
- more tests


=== Zope3/src/zope/fieldindex/fieldindex.py 1.4 => 1.5 ===
--- Zope3/src/zope/fieldindex/fieldindex.py:1.4	Thu Mar 27 04:28:36 2003
+++ Zope3/src/zope/fieldindex/fieldindex.py	Thu Mar 27 05:16:25 2003
@@ -33,7 +33,6 @@
     def __init__(self):
         self.clear()
 
-
     def clear(self):
         """ initialize forward and reverse mappings """
 
@@ -44,16 +43,13 @@
         # The reverse index maps a docid to its index value
         self._rev_index = IOBTree()
 
-
     def documentCount(self):
         """Return the number of documents in the index."""
         return len(self._rev_index)
 
-
     def has_doc(self, docid):
         return bool(self._rev_index.has_key(docid))
 
-
     def index_doc(self, docid, value):
 
         if self.has_doc(docid):       # unindex doc if present
@@ -65,7 +61,6 @@
         self._fwd_index[value].insert(docid)
         self._rev_index[docid] = value
 
-
     def unindex_doc(self, docid):
 
         try:      # ignore non-existing docids, don't raise
@@ -81,10 +76,8 @@
                 del self._fwd_index[value]
         except: pass
 
-
     def search(self, values):
 
-
         # values can either be a single value or a sequence of
         # values to be searched.
 
@@ -104,7 +97,10 @@
         
             try: result = IISet(self._fwd_index[values])
             except: result = IISet()    
-            
 
         return result 
+
+    def rangesearch(self, minvalue, maxvalue):
+    
+        return IISet(self._fwd_index.keys(minvalue, maxvalue))
 


=== Zope3/src/zope/fieldindex/ifieldindex.py 1.2 => 1.3 ===
--- Zope3/src/zope/fieldindex/ifieldindex.py:1.2	Wed Mar 26 05:53:08 2003
+++ Zope3/src/zope/fieldindex/ifieldindex.py	Thu Mar 27 05:16:25 2003
@@ -29,11 +29,24 @@
            Return an IISet of docids
         """
 
+    def rangesearch(minval, maxval):
+        """ Execute a range search.
+
+           Return an IISet of docids for all docs where
+
+           minval <= value <= maxval   if minval<=maxval and 
+                                       both minval and maxval are not None
+
+           value <= maxval             if minval is not None 
+
+           value >= minval             if maxval is not None
+        """             
+
     def index_doc(docid, value):
         """ index the value 'value' for a given docid"""
 
     def unindex_doc(docid):
-        """ unindex document with document ID docid """
+        """unindex document with document ID docid """
 
     def has_doc(docid):
         """Returns true if docid is an id of a document in the index"""