diff options
author | Bruno Wagner <bwagner@thoughtworks.com> | 2014-10-17 14:58:19 +0200 |
---|---|---|
committer | Bruno Wagner <bwagner@thoughtworks.com> | 2014-10-17 15:03:56 +0200 |
commit | 70ecb8829f8161ede22fcb38274c6e57a9819b98 (patch) | |
tree | 4f2b773c7b036ee313597e39fab4f9f5a142db08 /service/pixelated | |
parent | 4844d927aeac67cc8a41dac77eea21dfb038c984 (diff) |
#102 #113 Sorting through search, and ignoring duplicate results on searches
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/search.py | 11 | ||||
-rw-r--r-- | service/pixelated/controllers/mails_controller.py | 1 |
2 files changed, 7 insertions, 5 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index a187b444..237a4fcb 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -21,6 +21,7 @@ from whoosh.fields import * from whoosh.qparser import QueryParser from whoosh import sorting from pixelated.support.functional import unique +import dateutil.parser class SearchEngine(object): @@ -94,6 +95,7 @@ class SearchEngine(object): cc=ID(stored=False), bcc=ID(stored=False), subject=TEXT(stored=False), + date=TEXT(stored=False, sortable=True), body=TEXT(stored=False), tag=KEYWORD(stored=True, commas=True), flags=KEYWORD(stored=True, commas=True), @@ -115,6 +117,7 @@ class SearchEngine(object): index_data = { 'sender': unicode(header.get('from', '')), 'subject': unicode(header.get('subject', '')), + 'date': unicode(header.get('date', '')), 'to': unicode(header.get('to', '')), 'cc': unicode(header.get('cc', '')), 'bcc': unicode(header.get('bcc', '')), @@ -144,8 +147,8 @@ class SearchEngine(object): def _search_all_mails(self, query): with self._index.searcher() as searcher: - results = searcher.search(query, limit=None) - return [mail['ident'] for mail in results] + results = searcher.search(query, sortedby='date', limit=None) + return {mail['ident'] for mail in results} def _paginated_search_mails(self, query, window, page): page = int(page) if int(page) > 1 else 1 @@ -153,8 +156,8 @@ class SearchEngine(object): with self._index.searcher() as searcher: tags_facet = sorting.FieldFacet('tag', allow_overlap=True, maptype=sorting.Count) - results = searcher.search_page(query, page, pagelen=window, groupedby=tags_facet) - return [mail['ident'] for mail in results], sum(results.results.groups().values()) + results = searcher.search_page(query, page, pagelen=window, groupedby=tags_facet, sortedby='date') + return {mail['ident'] for mail in results}, sum(results.results.groups().values()) def prepare_query(self, query): query = ( diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py index 6e971dcd..b850d24d 100644 --- a/service/pixelated/controllers/mails_controller.py +++ b/service/pixelated/controllers/mails_controller.py @@ -31,7 +31,6 @@ class MailsController: def mails(self, _request=request): mail_ids, total = self._search_engine.search(_request.args.get('q'), _request.args.get('w'), _request.args.get('p')) mails = self._mail_service.mails(mail_ids) - mails = sorted(mails, key=lambda mail: dateparser.parse(mail.date), reverse=True) response = { "stats": { |