From 880bba5dd4cb370809c7a949719f015cae3126fa Mon Sep 17 00:00:00 2001 From: Bruno Wagner Date: Fri, 17 Oct 2014 18:53:59 +0200 Subject: Date is now stored as number, and is correctly used for sorting --- service/pixelated/adapter/search.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'service/pixelated/adapter/search.py') diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index 237a4fcb..ac68849c 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -21,7 +21,7 @@ from whoosh.fields import * from whoosh.qparser import QueryParser from whoosh import sorting from pixelated.support.functional import unique -import dateutil.parser +from pixelated.support.date import milliseconds class SearchEngine(object): @@ -95,7 +95,7 @@ class SearchEngine(object): cc=ID(stored=False), bcc=ID(stored=False), subject=TEXT(stored=False), - date=TEXT(stored=False, sortable=True), + date=NUMERIC(stored=False, sortable=True, bits=64, signed=False), body=TEXT(stored=False), tag=KEYWORD(stored=True, commas=True), flags=KEYWORD(stored=True, commas=True), @@ -113,11 +113,10 @@ class SearchEngine(object): header = mdict['header'] tags = mdict.get('tags', []) tags.append(mail.mailbox_name.lower()) - index_data = { 'sender': unicode(header.get('from', '')), 'subject': unicode(header.get('subject', '')), - 'date': unicode(header.get('date', '')), + 'date': milliseconds(header.get('date', '')), 'to': unicode(header.get('to', '')), 'cc': unicode(header.get('cc', '')), 'bcc': unicode(header.get('bcc', '')), @@ -147,8 +146,9 @@ class SearchEngine(object): def _search_all_mails(self, query): with self._index.searcher() as searcher: - results = searcher.search(query, sortedby='date', limit=None) - return {mail['ident'] for mail in results} + sorting_facet = sorting.FieldFacet('date', reverse=True) + results = searcher.search(query, sortedby=sorting_facet, reverse=True, limit=None) + return unique([mail['ident'] for mail in results]) def _paginated_search_mails(self, query, window, page): page = int(page) if int(page) > 1 else 1 @@ -156,8 +156,9 @@ 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, sortedby='date') - return {mail['ident'] for mail in results}, sum(results.results.groups().values()) + sorting_facet = sorting.FieldFacet('date', reverse=True) + results = searcher.search_page(query, page, pagelen=window, groupedby=tags_facet, sortedby=sorting_facet) + return unique([mail['ident'] for mail in results]), sum(results.results.groups().values()) def prepare_query(self, query): query = ( -- cgit v1.2.3