Skip to content

Commit 42b1b35

Browse files
author
Richard Jones
committed
Some TODOs
1 parent 630b663 commit 42b1b35

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

roundup/indexer.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# that promote freedom, but obviously am giving up any rights
1515
# to compel such.
1616
#
17-
#$Id: indexer.py,v 1.8 2002-07-09 21:53:38 gmcm Exp $
17+
#$Id: indexer.py,v 1.9 2002-07-14 06:11:16 richard Exp $
1818
'''
1919
This module provides an indexer class, RoundupIndexer, that stores text
2020
indices in a roundup instance. This class makes searching the content of
@@ -41,11 +41,16 @@ def __init__(self, db_path):
4141
self.changed = 0
4242

4343
# see if we need to reindex because of a change in code
44+
version = os.path.join(self.indexdb_path, 'version')
4445
if (not os.path.exists(self.indexdb_path) or
45-
not os.path.exists(os.path.join(self.indexdb_path, 'version'))):
46-
# TODO: if the version file exists (in the future) we'll want to
47-
# check the value in it - for now the file itself is a flag
46+
not os.path.exists(version)):
47+
# for now the file itself is a flag
4848
self.force_reindex()
49+
elif os.path.exists(version):
50+
version = open(version).read()
51+
# check the value and reindex if it's not the latest
52+
if version != '1':
53+
self.force_reindex()
4954

5055
def force_reindex(self):
5156
'''Force a reindex condition
@@ -244,8 +249,8 @@ def load_index(self, reload=0, wordlist=None):
244249
try:
245250
f = open(self.indexdb + segment, 'rb')
246251
except IOError, error:
247-
if error.errno != errno.ENOENT:
248-
raise
252+
# probably just nonexistent segment index file
253+
if error.errno != errno.ENOENT: raise
249254
else:
250255
pickle_str = zlib.decompress(f.read())
251256
f.close()
@@ -275,10 +280,9 @@ def save_index(self):
275280
for segment in self.segments:
276281
try:
277282
os.remove(self.indexdb + segment)
278-
except OSError:
283+
except OSError, error:
279284
# probably just nonexistent segment index file
280-
# TODO: make sure it's an EEXIST
281-
pass
285+
if error.errno != errno.EEXIST: raise
282286

283287
# First write the much simpler filename/fileid dictionaries
284288
dbfil = {'WORDS':None, 'FILES':self.files, 'FILEIDS':self.fileids}
@@ -329,6 +333,12 @@ def index_loaded(self):
329333

330334
#
331335
#$Log: not supported by cvs2svn $
336+
#Revision 1.8 2002/07/09 21:53:38 gmcm
337+
#Optimize Class.find so that the propspec can contain a set of ids to match.
338+
#This is used by indexer.search so it can do just one find for all the index matches.
339+
#This was already confusing code, but for common terms (lots of index matches),
340+
#it is enormously faster.
341+
#
332342
#Revision 1.7 2002/07/09 21:38:43 richard
333343
#Only save the index if the thing is loaded and changed. Also, don't load
334344
#the index just for a save.

0 commit comments

Comments
 (0)