diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-08-01 12:20:36 +0000 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-08-01 13:36:17 +0000 |
commit | 070871070e62fce367c55ec52579f4680b3d3980 (patch) | |
tree | 6b9adfc64686e7b061dd22192c44a29f5cfb320e | |
parent | ea538b0cba128ec298de667e7dd5646312415909 (diff) | |
download | kittystore-070871070e62fce367c55ec52579f4680b3d3980.tar.gz kittystore-070871070e62fce367c55ec52579f4680b3d3980.tar.xz kittystore-070871070e62fce367c55ec52579f4680b3d3980.zip |
Store the user_id in the search index
-rw-r--r-- | kittystore/__init__.py | 1 | ||||
-rw-r--r-- | kittystore/storm/search.py | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/kittystore/__init__.py b/kittystore/__init__.py index 272c19c..5a97253 100644 --- a/kittystore/__init__.py +++ b/kittystore/__init__.py @@ -40,6 +40,7 @@ def get_store(settings, debug=None): store = get_storm_store(settings, debug) if settings.KITTYSTORE_SEARCH_INDEX is not None: store.search_index.initialize_with(store) + store.search_index.upgrade(store) return store diff --git a/kittystore/storm/search.py b/kittystore/storm/search.py index 094b7eb..4a7b1fc 100644 --- a/kittystore/storm/search.py +++ b/kittystore/storm/search.py @@ -15,6 +15,7 @@ license. from __future__ import absolute_import import os +import shutil from whoosh.index import create_in, exists_in, open_dir from whoosh.fields import Schema, ID, TEXT, DATETIME, KEYWORD @@ -31,6 +32,7 @@ def email_to_search_doc(email): "list_name": email.list_name, "message_id": email.message_id, "sender": u"%s %s" % (email.sender_name, email.sender_email), + "user_id": email.user_id or "", "subject": email.subject, "content": email.content, "date": email.date, # UTC @@ -53,6 +55,7 @@ class SearchEngine(object): list_name=ID(stored=True), message_id=ID(stored=True), sender=TEXT(field_boost=1.5), + user_id=TEXT, subject=TEXT(field_boost=2.0, analyzer=stem_ana), content=TEXT(analyzer=stem_ana), date=DATETIME(), @@ -141,3 +144,11 @@ class SearchEngine(object): return # index already exists messages = store.db.find(Email).order_by(Email.archived_date) self.add_batch(messages) + + def upgrade(self, store): + """Upgrade the schema""" + if "user_id" not in self.index.schema or True: + print "Rebuilding the search index to include the new user_id field..." + shutil.rmtree(self.location) + self._index = None + self.initialize_with(store) |