diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/adapter/search.py | 17 | ||||
-rw-r--r-- | service/pixelated/support/date.py | 9 |
2 files changed, 18 insertions, 8 deletions
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 = ( diff --git a/service/pixelated/support/date.py b/service/pixelated/support/date.py index 329b8bfe..8a2daaf0 100644 --- a/service/pixelated/support/date.py +++ b/service/pixelated/support/date.py @@ -14,9 +14,18 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import datetime +import dateutil.parser from dateutil.tz import tzlocal def iso_now(): return datetime.datetime.now(tzlocal()).isoformat() + + +def milliseconds(date): + date = dateutil.parser.parse(date) + date = date.replace(tzinfo=None) + epoch = datetime.datetime.utcfromtimestamp(0) + delta = date - epoch + return int(delta.total_seconds() * 1000) |