[Zope3-checkins] CVS: Zope3/src/zope/fieldindex - fieldindex.py:1.7

Andreas Jung andreas@andreas-jung.com
Mon, 31 Mar 2003 01:02:01 -0500


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

Modified Files:
	fieldindex.py 
Log Message:
- some more refactoring to make FieldIndex reusable as base class for
  a KeywordIndex


=== Zope3/src/zope/fieldindex/fieldindex.py 1.6 => 1.7 ===
--- Zope3/src/zope/fieldindex/fieldindex.py:1.6	Thu Mar 27 06:19:51 2003
+++ Zope3/src/zope/fieldindex/fieldindex.py	Mon Mar 31 01:02:00 2003
@@ -35,11 +35,8 @@
 
     def clear(self):
         """ initialize forward and reverse mappings """
-
-        # The forward index maps indexed values to a sequence
-        # of docids
+        # The forward index maps indexed values to a sequence of docids
         self._fwd_index = OOBTree()
-
         # The reverse index maps a docid to its index value
         self._rev_index = IOBTree()
 
@@ -51,18 +48,12 @@
         return bool(self._rev_index.has_key(docid))
 
     def index_doc(self, docid, value):
-
         if self.has_doc(docid):       # unindex doc if present
             self.unindex_doc(docid)
-
-        if not self._fwd_index.has_key(value):
-            self._fwd_index[value] = IITreeSet()
-
-        self._fwd_index[value].insert(docid)
-        self._rev_index[docid] = value
+        self._insert_forward(docid, value)
+        self._insert_reverse(docid, value)
 
     def unindex_doc(self, docid):
-
         try:      # ignore non-existing docids, don't raise
             value = self._rev_index[docid]
         except KeyError: 
@@ -77,30 +68,30 @@
         except KeyError: pass
 
     def search(self, values):
-
         # values can either be a single value or a sequence of
         # values to be searched.
-
         if isinstance(values , (ListType, TupleType)):
-           
             result = IISet()
-
             for value in values:
-
                 try: r = IISet(self._fwd_index[value])
                 except KeyError: continue
-
                 # the results of all subsearches are combined using OR
                 result = union(result, r)
-
         else:
-        
             try: result = IISet(self._fwd_index[values])
             except KeyError: result = IISet()    
 
         return result 
 
     def rangesearch(self, minvalue, maxvalue):
-    
         return IISet(self._fwd_index.keys(minvalue, maxvalue))
 
+    def _insert_forward(self, docid, value):
+        """ insert into forward index """
+        if not self._fwd_index.has_key(value):
+            self._fwd_index[value] = IITreeSet()
+        self._fwd_index[value].insert(docid)
+
+    def _insert_reverse(self, docid, value):
+        """ insert into reverse index """
+        self._rev_index[docid] = value