[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - TextIndexNG.py:1.2.2.30
Andreas Jung
andreas@digicool.com
Wed, 13 Feb 2002 12:05:37 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv8996
Modified Files:
Tag: ajung-textindexng-branch
TextIndexNG.py
Log Message:
added support for exact phrase searches
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.29 => 1.2.2.30 ===
for docId in res[0]:
bucket[ docId ] = 1
-
- print bucket
+
return res[0], (self.id, )
@@ -566,6 +565,7 @@
txI = self.txIntersection
txU = self.txUnion
txN = self.txNear
+ txQ = self.txQuote
debug('Query: ',q)
@@ -630,7 +630,6 @@
if not self.useSimilarity:
raise TextIndexNGException, 'Similarity search is not enabled'
-
# Lookup list of wordIds (usually should contain only *one*)
wids = self._PROX_LEX.get(word)
debug("\tWids: ", wids)
@@ -692,10 +691,21 @@
debug("\treturn: ",r)
return r
-
- def txNear(self, *sets):
+
+ def txQuote(self, *sets):
+ """ quote is a special case of near search where the near-
+ distance is one and we only search to the right
+ """
+ return apply(self.txNear,sets,{'distance':1,'bidirectional':1})
+
+
+ def txNear(self, *sets, **kw):
""" perform near search on results sets """
+
+
+ distance = kw.get('distance',self.nearDistance)
+ bidirectional = kw.get('bidirectional',1)
# One resultset consists of an IISet() or documentIds and
# tuple whose first element is the word (from LexiconLookup())
@@ -707,6 +717,8 @@
r = self.txIntersection(*sets)
docIds = r.docIds()
+ debug('txNear (%s)' % str(kw))
+
# Now we determine for every document the positions of all
# the words inside the document. then we compare all the positions
# to determine neighbourship
@@ -718,12 +730,13 @@
for docId in docIds:
+ # the posMap is a list of tuples(word,IISet[positions])
posMap = self.positionsFromDocumentLookup(docId, words)
- debug("Position Map for NEAR:")
- for item in posMap: debug("\t%s" % str(item))
+ debug("\tPosition Map for NEAR:")
+ for item in posMap: debug("\t\t%s" % str(item))
- if len(self.checkPositionMap(posMap,self.nearDistance)) > 0:
+ if len(self.checkPositionMap(posMap, distance, bidirectional)) > 0:
res_docIds.insert(docId)
r = ResultSet( res_docIds, words)
@@ -732,7 +745,7 @@
return r
- def checkPositionMap(self, posMap, nearDistance):
+ def checkPositionMap(self, posMap, nearDistance, bidirectional=1):
""" check if a PositionMap represents a valid match for
a near search
"""
@@ -762,7 +775,7 @@
num = 0
for word,posLst in posMap:
- keys = posLst.keys( pos-nearDistance, pos+nearDistance)
+ keys = posLst.keys( pos-bidirectional*nearDistance, pos+nearDistance)
if len(keys)>0: num+=1