[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - TextIndexNG.py:1.2.2.4
Andreas Jung
andreas@zope.com
Sat, 5 Jan 2002 17:09:59 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv11642
Modified Files:
Tag: ajung-textindexng-branch
TextIndexNG.py
Log Message:
+ unindex_object()
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.3 => 1.2.2.4 ===
"""
-__version__ = '$Revision$'[11:-2]
+__version__ = '$Id$'
import re
import warnings
@@ -77,7 +77,7 @@
self.nearDistance = getattr(extra,'nearDistance', 5)
self.useProximity = getattr(extra,'useProximity', None)
- if self.lexicon== 'None': self.lexicon = None
+ if self.lexicon == 'None': self.lexicon = None
if self.useStemmer == 'None': self.useStemmer = None
self.clear()
@@ -123,6 +123,7 @@
self._v_getWordById = self._LEXICON.getWord
self._v_getIdByWord = self._LEXICON.get
+
def __nonzero__(self):
return not not self._unindex
@@ -146,8 +147,8 @@
idx[documentId].update(widLst)
-
def insertForwardEntry(self,wordId,pos,documentId):
+ """ insert entries for forward index """
# self._IDX is a mapping:
# wordId -> documentId -> [positions]
@@ -163,14 +164,6 @@
tree[documentId].insert(pos)
- # and insert reverse entry
- invidx = self._invIDX
- if invidx.has_key(documentId)==0:
- invidx[documentId] = IISet()
-
- invidx[document].insert(wordId)
-
-
def _printIndex(self):
@@ -230,6 +223,23 @@
self.insertBackwardEntries(self,widLst,documentId)
+
+ def unindex_object(self, documentId):
+ """ carefully unindex document with Id 'documentId'
+ index and do not fail if it does not exist
+ """
+
+ invIDX = self._invIDX
+ IDX = self._IDX
+
+ for wid in invIDX[documentId]:
+ IDX[wid].remove( documentId )
+
+ if len(IDX[wid])==0:
+ del IDX[wid]
+
+ del invIDX[documentID]
+
def __getitem__(self, word):
"""Return an InvertedIndex-style result "list"