From 0e682f97bf60b57d6991d52be8c0b77c5b8b5b28 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sun, 20 Dec 2009 12:00:07 +0000 Subject: fix range query for timestamp to do numerical comparison instead of lexical (#1342) With the current code, anything Xapian value-stored is converted to a string before querying, so numeric types end up as decimal strings. This won't work as expected because Xapian does lexical comparison. We need to use xapian.sortable_serialise() on numeric values to convert them to an (internal) format that will result in "numerical" comparison. Changes index content format, so needs an index rebuild. Prerequisite: #1437 Signed-off-by: Sascha Silbe --- diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py index 7c81cf6..4dfd620 100644 --- a/src/carquinyol/indexstore.py +++ b/src/carquinyol/indexstore.py @@ -63,7 +63,8 @@ _QUERY_VALUE_MAP = { class TermGenerator (xapian.TermGenerator): def index_document(self, document, properties): - document.add_value(_VALUE_TIMESTAMP, str(properties['timestamp'])) + document.add_value(_VALUE_TIMESTAMP, + xapian.sortable_serialise(float(properties['timestamp']))) document.add_value(_VALUE_TITLE, properties.get('title', '').strip()) self.set_document(document) @@ -143,6 +144,9 @@ class QueryParser (xapian.QueryParser): self._convert_value(info, start), self._convert_value(info, end)) def _convert_value(self, info, value): + if info['type'] in (float, int, long): + return xapian.sortable_serialise(info['type'](value)) + return str(info['type'](value)) def _parse_query_value(self, name, info, value): -- cgit v0.9.1