[Zope-CVS] CVS: Products/ZCTextIndex - CosineIndex.py:1.3 Lexicon.py:1.8 OkapiIndex.py:1.10 SetOps.py:1.2 ZCTextIndex.py:1.14
Guido van Rossum
guido@python.org
Thu, 16 May 2002 15:51:13 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv16536
Modified Files:
CosineIndex.py Lexicon.py OkapiIndex.py SetOps.py
ZCTextIndex.py
Log Message:
Fix queries of the form 'extension module C'.
=== Products/ZCTextIndex/CosineIndex.py 1.2 => 1.3 ===
def search(self, term):
wids = self._lexicon.termToWordIds(term)
+ if not wids:
+ return None # All docs match
+ if 0 in wids:
+ wids = filter(None, wids)
return mass_weightedUnion(self._search_wids(wids))
def search_glob(self, pattern):
@@ -123,6 +127,8 @@
def search_phrase(self, phrase):
wids = self._lexicon.termToWordIds(phrase)
+ if 0 in wids:
+ return IIBTree()
hits = mass_weightedIntersection(self._search_wids(wids))
if not hits:
return hits
@@ -157,6 +163,8 @@
N = float(len(self._docweight))
sum = 0.0
for wid in wids:
+ if wid == 0:
+ continue
wt = math.log(1.0 + N / len(self._wordinfo[wid]))
sum += wt ** 2.0
return scaled_int(math.sqrt(sum))
=== Products/ZCTextIndex/Lexicon.py 1.7 => 1.8 ===
wids = []
for word in last:
- wid = self._wids.get(word)
- if wid is not None:
- wids.append(wid)
+ wids.append(self._wids.get(word, 0))
return wids
def get_word(self, wid):
=== Products/ZCTextIndex/OkapiIndex.py 1.9 => 1.10 ===
def search(self, term):
wids = self._lexicon.termToWordIds(term)
+ if not wids:
+ return None # All docs match
+ if 0 in wids:
+ wids = filter(None, wids)
return mass_weightedUnion(self._search_wids(wids))
def search_glob(self, pattern):
@@ -117,6 +121,8 @@
def search_phrase(self, phrase):
wids = self._lexicon.termToWordIds(phrase)
+ if 0 in wids:
+ return IIBTree()
hits = mass_weightedIntersection(self._search_wids(wids))
if not hits:
return hits
=== Products/ZCTextIndex/SetOps.py 1.1 => 1.2 ===
def mass_weightedIntersection(L):
"A list of (mapping, weight) pairs -> their weightedIntersection IIBTree."
+ L = [(map, weight) for (map, weight) in L if map is not None]
if not L:
return IIBTree()
# Intersect with smallest first.
- L = L[:] # don't mutate the caller's L
L.sort(lambda x, y: cmp(len(x[0]), len(y[0])))
x, w = L[0]
dummy, result = weightedUnion(IIBTree(), x, 1, w)
=== Products/ZCTextIndex/ZCTextIndex.py 1.13 => 1.14 ===
tree = QueryParser().parseQuery(query)
results = tree.executeQuery(self.index)
+ if results is None:
+ return [], 0
chooser = NBest(nbest)
chooser.addmany(results.items())
return chooser.getbest(), len(results)