diff options
| author | Fábio Pio <fpio@thoughtworks.com> | 2014-12-17 17:18:54 -0200 | 
|---|---|---|
| committer | Fábio Pio <fpio@thoughtworks.com> | 2014-12-17 17:21:52 -0200 | 
| commit | 129800847138e802040d4ad53adc06b9776ac1c6 (patch) | |
| tree | 0ac419a91e4b9a71c3fabafc82f59d00343e4d4e | |
| parent | 8d71694e252aa517a696403327dae594b43744c0 (diff) | |
Fix issue #200 search works with base63 bodies
Now the search works with the decoded body too,
instead of only with the raw mail
| -rw-r--r-- | service/pixelated/adapter/search.py | 3 | ||||
| -rw-r--r-- | service/test/integration/search_test.py | 9 | ||||
| -rw-r--r-- | service/test/support/integration/soledad_test_base.py | 6 | 
3 files changed, 16 insertions, 2 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index d1e43735..3d71bab7 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -22,6 +22,7 @@ from pixelated.support.functional import flatten  from whoosh.index import FileIndex  from whoosh.fields import *  from whoosh.qparser import QueryParser +from whoosh.qparser import MultifieldParser  from whoosh.query import Term  from whoosh import sorting  from pixelated.support.functional import unique @@ -175,7 +176,7 @@ class SearchEngine(object):              .replace('-in:', 'AND NOT tag:')              .replace('in:all', '*')          ) -        return QueryParser('raw', self._index.schema).parse(query) +        return MultifieldParser(['raw', 'body'], self._index.schema).parse(query)      def remove_from_index(self, mail_id):          writer = self._index.writer() diff --git a/service/test/integration/search_test.py b/service/test/integration/search_test.py index 21326ec7..6deb4794 100644 --- a/service/test/integration/search_test.py +++ b/service/test/integration/search_test.py @@ -133,3 +133,12 @@ class SearchTest(SoledadTestBase):          results = self.get_mails_by_tag('inbox')          self.assertEqual(results[0].ident, input_mail2.ident)          self.assertEqual(results[1].ident, input_mail.ident) + +    def test_search_base64_body(self): +        body = u'bl\xe1' +        input_mail = MailBuilder().with_body(body.encode('utf-8')).build_input_mail() +        self.client.add_mail_to_inbox(input_mail) +        results = self.search(body) + +        self.assertGreater(len(results), 0, 'No results returned from search') +        self.assertEquals(results[0].ident, input_mail.ident )
\ No newline at end of file diff --git a/service/test/support/integration/soledad_test_base.py b/service/test/support/integration/soledad_test_base.py index 40181664..a000349e 100644 --- a/service/test/support/integration/soledad_test_base.py +++ b/service/test/support/integration/soledad_test_base.py @@ -35,8 +35,12 @@ class SoledadTestBase(unittest.TestCase):          self.client = AppTestClient()      def get_mails_by_tag(self, tag, page=1, window=100): +        tags = 'tag:%s' % tag +        return self.search(tags, page, window) + +    def search(self, query, page=1, window=100):          res, req = self.client.get("/mails", { -            'q': ['tag:%s' % tag], +            'q': [query],              'w': [str(window)],              'p': [str(page)]          })  | 
