From 88dbd2000afa43964d5a22e22a332820ebbbf777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 10 Jun 2019 15:56:05 +0200 Subject: [PATCH] index: Change the index format. Tantivy allows search results to be ordered by arbitrary index fields as long as they are a fast field and have the FastValue trait implemented. This trait is only for u64 and i64 fields implemented. To order the the search results by recency we need to add a unsigned field that stores the server timestamp of the message. --- pantalaimon/index.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pantalaimon/index.py b/pantalaimon/index.py index 4047028..5ba472a 100644 --- a/pantalaimon/index.py +++ b/pantalaimon/index.py @@ -84,12 +84,15 @@ class Index: self.name_field = schema_builder.add_text_field("name") self.topic_field = schema_builder.add_text_field("topic") - self.timestamp_field = schema_builder.add_date_field( + self.timestamp_field = schema_builder.add_unsigned_field( "server_timestamp" ) + self.date_field = schema_builder.add_date_field( + "message_date" + ) self.room_field = schema_builder.add_facet_field("room") - self.column_field = schema_builder.add_integer_field( + self.column_field = schema_builder.add_unsigned_field( "database_column", indexed=True, stored=True, @@ -110,12 +113,13 @@ class Index: room_facet = tantivy.Facet.from_string(room_path) - doc.add_integer(self.column_field, column_id) + doc.add_unsigned(self.column_field, column_id) doc.add_facet(self.room_field, room_facet) doc.add_date( - self.timestamp_field, + self.date_field, datetime.datetime.fromtimestamp(event.server_timestamp / 1000) ) + doc.add_unsigned(self.timestamp_field, event.server_timestamp) if isinstance(event, RoomMessageText): doc.add_text(self.body_field, event.body)