summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a27aa00)
raw | patch | inline | side by side (parent: a27aa00)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 9 Jul 2002 21:38:43 +0000 (21:38 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 9 Jul 2002 21:38:43 +0000 (21:38 +0000) |
the index just for a save.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@847 57a73879-2fb5-44c3-a270-3262357dd7e2
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@847 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/indexer.py | patch | blob | history |
diff --git a/roundup/indexer.py b/roundup/indexer.py
index d09e950d8102a1b6843ea8150d8068f8b491a7ba..a1edc712d848c6e8c97689ae2d9dbd8f768f1e5c 100644 (file)
--- a/roundup/indexer.py
+++ b/roundup/indexer.py
# that promote freedom, but obviously am giving up any rights
# to compel such.
#
-#$Id: indexer.py,v 1.6 2002-07-09 04:26:44 richard Exp $
+#$Id: indexer.py,v 1.7 2002-07-09 21:38:43 richard Exp $
'''
This module provides an indexer class, RoundupIndexer, that stores text
indices in a roundup instance. This class makes searching the content of
self.indexdb_path = os.path.join(db_path, 'indexes')
self.indexdb = os.path.join(self.indexdb_path, 'index.db')
self.reindex = 0
- self.casesensitive = 0
self.quiet = 9
+ self.changed = 0
# see if we need to reindex because of a change in code
if (not os.path.exists(self.indexdb_path) or
os.chmod(self.indexdb_path, 0775)
open(os.path.join(self.indexdb_path, 'version'), 'w').write('1\n')
self.reindex = 1
+ self.changed = 1
def should_reindex(self):
'''Should we reindex?
# make a reference to the file for this word
entry[file_index] = filedict[word]
+ # save needed
+ self.changed = 1
+
def splitter(self, text, ftype):
''' Split the contents of a text string into a list of 'words'
'''
if ftype == 'text/plain':
- words = self.text_splitter(text, self.casesensitive)
+ words = self.text_splitter(text)
else:
return []
return words
- def text_splitter(self, text, casesensitive=0):
+ def text_splitter(self, text):
"""Split text/plain string into a list of words
"""
- # Let's adjust case if not case-sensitive
- if not casesensitive:
- text = text.upper()
+ # case insensitive
+ text = text.upper()
# Split the raw text, losing anything longer than 25 characters
# since that'll be gibberish (encoded text or somesuch) or shorter
if not 2 < len(word) < 25:
# word outside the bounds of what we index - ignore
continue
- if not self.casesensitive:
- word = word.upper()
+ word = word.upper()
entry = self.words.get(word) # For each word, get index
entries[word] = entry # of matching files
if not entry: # Nothing for this one word (fail)
self.words = db['WORDS']
self.files = db['FILES']
self.fileids = db['FILEIDS']
+ self.changed = 0
def save_index(self):
- # make sure we're loaded
- self.load_index()
+ # only save if the index is loaded and changed
+ if not self.index_loaded() or not self.changed:
+ return
# brutal space saver... delete all the small segments
for segment in self.segments:
pickle_fh.write(zlib.compress(pickle_str))
os.chmod(filename, 0664)
+ # save done
+ self.changed = 0
+
def purge_entry(self, identifier):
''' Remove a file from file index and word index
'''
if occurs.has_key(file_index):
del occurs[file_index]
+ # save needed
+ self.changed = 1
+
def index_loaded(self):
return (hasattr(self,'fileids') and hasattr(self,'files') and
hasattr(self,'words'))
#
#$Log: not supported by cvs2svn $
+#Revision 1.6 2002/07/09 04:26:44 richard
+#We're indexing numbers now, and _underscore words
+#
#Revision 1.5 2002/07/09 04:19:09 richard
#Added reindex command to roundup-admin.
#Fixed reindex on first access.