[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - TextIndexNG.py:1.2.2.11
Andreas Jung
andreas@digicool.com
Tue, 15 Jan 2002 12:43:30 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv5446
Modified Files:
Tag: ajung-textindexng-branch
TextIndexNG.py
Log Message:
added union/intersection support
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.10 => 1.2.2.11 ===
from OFS.SimpleItem import SimpleItem
from Acquisition import Implicit
-from Products.PluginIndexes.TextIndexNG.ResultListNG import ResultListNG
+from Products.PluginIndexes.TextIndexNG.ResultSet import ResultSet
from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.util import parseIndexRequest
from BTrees.IOBTree import IOBTree
from BTrees.OOBTree import OOBTree
from BTrees.IIBTree import IIBTree, IIBucket, IISet
+from BTrees.IIBTree import intersection as IntIntersection, union as IntUnion
+from BTrees.OOBTree import intersection as ObjIntersection, union as ObjUnion
from BTrees.IIBTree import weightedIntersection
from LexiconNG import LexiconNG
@@ -508,6 +510,11 @@
def query(self, q):
""" to be finished """
+ LL = self.LexiconLookup
+ txIntersection = self.txIntersection
+ txUnion = self.txUnion
+ txNear = self.txNear
+
print "query",q
self._parser.DoParse1( q )
@@ -519,7 +526,90 @@
print "result",res
- return res
+ # Bah....this sucks
+ return res.docIds(), (self.id,)
+
+
+ def LexiconLookup(self,word):
+ """ search a word in the lexicon and return a ResultSet
+ of found documents
+ """
+
+ debug("LexionLookup: ",word)
+
+ # Stem the word if necessary
+ if self.useStemmer:
+ word = self._v_stemmerfunc(word)
+ debug("\tStemming: ", word)
+
+ # Lookup list of wordIds (usually should contain only *one*)
+ wids = self._v_getIdByWord(word)
+ debug("\tWids: ", wids)
+
+ # Retrieve list of docIds for that wordId
+ # XXX: internal storage only !
+
+ # docIds is an IOBTree and contains the mapping
+ # (documentId, list of positions) for one word/wid
+ docIds = self._IDX.get(wids[0])
+
+ debug('\tDocIds: ', list(docIds.keys()))
+ debug('\tPositions: ', list(docIds.values()))
+
+ r = ResultSet( docIds, (word,))
+
+ return r
+
+
+ def txIntersection(self, *sets):
+ """ perform intersection of ResultSets """
+
+ debug("txIntersection")
+
+ docIds = None
+ words = None
+
+ for set in sets:
+
+ debug("\tset: ",set)
+
+ docIds = IntIntersection(docIds, set.docIds())
+ words = ObjUnion(words, set.words())
+
+ r = ResultSet( docIds, words)
+ debug("\treturn: ",r)
+
+ return r
+
+
+
+ def txUnion(self, *sets):
+ """ perform union of ResultSets """
+
+ debug("txUnion")
+
+ docIds = None
+ words = None
+
+ for set in sets:
+
+ debug("\tset: ",set)
+
+ docIds = IntUnion(docIds, set.docIds())
+ words = ObjUnion(words, set.words())
+
+ r = ResultSet( docIds, words)
+ debug("\treturn: ",r)
+
+ return r
+
+
+ def txNear(self, r1, r2):
+ """ perform near intersection of two ResultSets """
+
+
+
+
def positionsFromDocumentLookup(self,docId, words):