diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-11-15 14:40:30 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-11-15 14:40:30 +0100 |
commit | d2dd628746492a811075d9385af4afd0a98f86cf (patch) | |
tree | e18c65d11529685cd9d80cc048d829f52f8b2541 | |
parent | a847708a435eb1954f994f71f671c0c275ad476c (diff) | |
download | kittystore-d2dd628746492a811075d9385af4afd0a98f86cf.tar.gz kittystore-d2dd628746492a811075d9385af4afd0a98f86cf.tar.xz kittystore-d2dd628746492a811075d9385af4afd0a98f86cf.zip |
Be less verbose by default
-rw-r--r-- | kittystore/search.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/kittystore/search.py b/kittystore/search.py index 781bf8b..8b1cba0 100644 --- a/kittystore/search.py +++ b/kittystore/search.py @@ -124,12 +124,13 @@ class SearchEngine(object): def optimize(self): return self.index.optimize() - def add_batch(self, documents): + def add_batch(self, documents, debug=False): """ See http://pythonhosted.org/Whoosh/batch.html """ - sys.stdout.write("Indexing all messages") - sys.stdout.flush() + if debug: + sys.stdout.write("Indexing all messages") + sys.stdout.flush() # Don't use optimizations below, it will eat up lots of memory and can # go as far as preventing forking (OSError), tested on a 3GB VM with # the Fedora archives @@ -147,7 +148,7 @@ class SearchEngine(object): if IMessage.providedBy(doc): doc = email_to_search_doc(doc) writer.add_document(**doc) - if num % 100 == 0: + if debug and num % 100 == 0: sys.stdout.write(".") sys.stdout.flush() except Exception: @@ -155,15 +156,16 @@ class SearchEngine(object): raise else: writer.commit() - sys.stdout.write("\n") - sys.stdout.flush() + if debug: + sys.stdout.write("\n") + sys.stdout.flush() def initialize_with(self, store): """Create and populate the index with the contents of a Store""" if not os.path.isdir(self.location): os.makedirs(self.location) self._index = create_in(self.location, self._get_schema()) - self.add_batch(store.get_all_messages()) + self.add_batch(store.get_all_messages(), store.debug) def needs_upgrade(self): if not exists_in(self.location): |