Commit 6369fa88 authored by Jim Fulton's avatar Jim Fulton

Got rid of most try/excepts.

parent dbba17b5
...@@ -127,8 +127,8 @@ Notes on a new text index design ...@@ -127,8 +127,8 @@ Notes on a new text index design
$Id: TextIndex.py,v 1.8 1997/12/02 19:36:19 jeffrey Exp $''' $Id: TextIndex.py,v 1.9 1998/02/05 15:24:22 jim Exp $'''
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
from Globals import Persistent from Globals import Persistent
import BTree, IIBTree import BTree, IIBTree
...@@ -222,26 +222,23 @@ class TextIndex(Persistent): ...@@ -222,26 +222,23 @@ class TextIndex(Persistent):
else: d[s]=1 else: d[s]=1
index=self._index index=self._index
indexed=index.has_key
if un: if un:
for word,score in d.items(): for word,score in d.items():
try: if indexed(word):
r=index[word] r=index[word]
if type(r) is tupleType: del index[word] if type(r) is tupleType: del index[word]
elif type(r) is dictType: else:
try: del r[id] if r.has_key(id): del r[id]
except: pass if type(r) is dictType:
if len(r) < 2: if len(r) < 2:
if r: if r:
for k, v in r.items(): index[word]=k,v for k, v in r.items(): index[word]=k,v
else: del index[word] else: del index[word]
else: index[word]=r else: index[word]=r
else:
try: del r[id]
except: pass
except KeyError: pass
else: else:
for word,score in d.items(): for word,score in d.items():
try: if indexed(word):
r=index[word] r=index[word]
if type(r) is tupleType: if type(r) is tupleType:
r={r[0]:r[1]} r={r[0]:r[1]}
...@@ -255,8 +252,7 @@ class TextIndex(Persistent): ...@@ -255,8 +252,7 @@ class TextIndex(Persistent):
r[id]=score r[id]=score
index[word]=r index[word]=r
else: r[id]=score else: r[id]=score
except KeyError: else: index[word]=id,score
index[word]=id,score
def _subindex(self, isrc, d, old, last): def _subindex(self, isrc, d, old, last):
...@@ -278,8 +274,9 @@ class TextIndex(Persistent): ...@@ -278,8 +274,9 @@ class TextIndex(Persistent):
if len(src) == 1: if len(src) == 1:
src=src[0] src=src[0]
if src[:1]=='"' and src[-1:]=='"': return self[src] if src[:1]=='"' and src[-1:]=='"': return self[src]
try: r=self._index[word] index=self._index
except: r={} if index.has_key(word): r=self._index[word]
else: r={}
return ResultList(r,(word,),self) return ResultList(r,(word,),self)
r=None r=None
...@@ -306,10 +303,11 @@ class TextIndex(Persistent): ...@@ -306,10 +303,11 @@ class TextIndex(Persistent):
id=self.id id=self.id
try: keys=request["%s/%s" % (cid,id)] cidid="%s/%s" % (cid,id)
except: has_key=request.has_key
try: keys=request[id] if has_key(cidid): keys=request[cidid]
except: return None elif has_key(id): keys=request[id]
else: return None
if type(keys) is not ListType: keys=[keys] if type(keys) is not ListType: keys=[keys]
r=None r=None
...@@ -448,6 +446,7 @@ def parse2(q, default_operator, ...@@ -448,6 +446,7 @@ def parse2(q, default_operator,
): ):
'''Find operators and operands''' '''Find operators and operands'''
i = 0 i = 0
isop=operator_dict.has_key
while (i < len(q)): while (i < len(q)):
if (type(q[i]) is ListType): q[i] = parse2(q[i], default_operator) if (type(q[i]) is ListType): q[i] = parse2(q[i], default_operator)
...@@ -455,8 +454,9 @@ def parse2(q, default_operator, ...@@ -455,8 +454,9 @@ def parse2(q, default_operator,
if ((i % 2) != 0): if ((i % 2) != 0):
# This word should be an operator; if it is not, splice in # This word should be an operator; if it is not, splice in
# the default operator. # the default operator.
try: q[i] = operator_dict[q[i]]
except: q[i : i] = [ default_operator ] if isop(q[i]): q[i] = operator_dict[q[i]]
else: q[i : i] = [ default_operator ]
i = i + 1 i = i + 1
...@@ -626,6 +626,9 @@ for word in stop_words: stop_word_dict[word]=None ...@@ -626,6 +626,9 @@ for word in stop_words: stop_word_dict[word]=None
############################################################################## ##############################################################################
# #
# $Log: TextIndex.py,v $ # $Log: TextIndex.py,v $
# Revision 1.9 1998/02/05 15:24:22 jim
# Got rid of most try/excepts.
#
# Revision 1.8 1997/12/02 19:36:19 jeffrey # Revision 1.8 1997/12/02 19:36:19 jeffrey
# fixed bug in .clear() method # fixed bug in .clear() method
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment