summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-10 14:14:42 +0200
committerDuda Dornelles <ddornell@thoughtworks.com>2014-10-10 14:14:46 +0200
commit622631a2007c60a4bf34ca1ce0713b339180e435 (patch)
tree2ca525a69e3dc020d9e966975a20805acfabb0fd /service
parent6b2bf282db6d889e633af6b8771d2393c335131d (diff)
Using file index for whoosh and fixing functional tests
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/search.py20
-rw-r--r--service/test/functional/features/steps/data_setup.py4
-rw-r--r--service/test/support/integration_helper.py7
3 files changed, 19 insertions, 12 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py
index 6c64cc40..e68e8111 100644
--- a/service/pixelated/adapter/search.py
+++ b/service/pixelated/adapter/search.py
@@ -1,12 +1,17 @@
+import os
+import whoosh.index
from whoosh.fields import *
-from whoosh.filedb.filestore import RamStorage
from whoosh.qparser import QueryParser
class SearchEngine(object):
__slots__ = '_index'
+ INDEX_FOLDER = '~/.leap/search_index'
+
def __init__(self):
+ if not os.path.exists(self.INDEX_FOLDER):
+ os.makedirs(self.INDEX_FOLDER)
self._index = self._create_index()
def _mail_schema(self):
@@ -21,12 +26,11 @@ class SearchEngine(object):
tag=KEYWORD(stored=False, commas=True))
def _create_index(self):
- return RamStorage().create_index(self._mail_schema(), indexname='mails')
+ return whoosh.index.create_in(self.INDEX_FOLDER, self._mail_schema(), indexname='mails')
def index_mail(self, mail):
- writer = self._index.writer()
- self._index_mail(writer, mail)
- writer.commit()
+ with self._index.writer() as writer:
+ self._index_mail(writer, mail)
def _index_mail(self, writer, mail):
mdict = mail.as_dict()
@@ -43,16 +47,12 @@ class SearchEngine(object):
'body': unicode(mdict['body']),
'ident': unicode(mdict['ident'])
}
-
writer.update_document(**index_data)
def index_mails(self, mails):
- writer = self._index.writer()
- try:
+ with self._index.writer() as writer:
for mail in mails:
self._index_mail(writer, mail)
- finally:
- writer.commit()
def search(self, query):
query = query.replace('\"', '')
diff --git a/service/test/functional/features/steps/data_setup.py b/service/test/functional/features/steps/data_setup.py
index 2d250c92..4f70a8db 100644
--- a/service/test/functional/features/steps/data_setup.py
+++ b/service/test/functional/features/steps/data_setup.py
@@ -19,5 +19,5 @@ from test.support.integration_helper import MailBuilder
@given('I have a mail in my inbox')
def add_mail_impl(context):
- mail = MailBuilder().build_input_mail()
- context.mailboxes.inbox().add(mail)
+ input_mail = MailBuilder().build_input_mail()
+ context.soledad_test_base.add_mail_to_inbox(input_mail)
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index e776e3c3..fdc507ea 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -112,6 +112,10 @@ class SoledadTestBase:
def setup_soledad(self):
unstub() # making sure all mocks from other tests are reset
+ # making sure soledad test folder is not there
+ if (os.path.isdir(soledad_test_folder)):
+ os.rmdir(soledad_test_folder)
+
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "test@pixelated.org"
@@ -129,7 +133,10 @@ class SoledadTestBase:
self.tag_service = TagService(self.tag_index)
self.draft_service = DraftService(self.pixelated_mailboxes)
self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service)
+
+ SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
self.search_engine = SearchEngine()
+
self.search_engine.index_mails(self.mail_service.all_mails())
pixelated.user_agent.mail_service = self.mail_service