From: Sascha Silbe <sascha@silbe.org>
Subject: [PATCH] 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 <sascha@silbe.org>
---
src/carquinyol/indexstore.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 09914e9..1ef4638 100644
a
|
b
|
_QUERY_VALUE_MAP = { |
63 | 63 | class TermGenerator (xapian.TermGenerator): |
64 | 64 | |
65 | 65 | def index_document(self, document, properties): |
66 | | document.add_value(_VALUE_TIMESTAMP, str(properties['timestamp'])) |
| 66 | document.add_value(_VALUE_TIMESTAMP, |
| 67 | xapian.sortable_serialise(float(properties['timestamp']))) |
67 | 68 | document.add_value(_VALUE_TITLE, properties.get('title', '').strip()) |
68 | 69 | |
69 | 70 | self.set_document(document) |
… |
… |
class QueryParser (xapian.QueryParser): |
143 | 144 | self._convert_value(info, start), self._convert_value(info, end)) |
144 | 145 | |
145 | 146 | def _convert_value(self, info, value): |
| 147 | if info['type'] in (float, int, long): |
| 148 | return xapian.sortable_serialise(info['type'](value)) |
| 149 | |
146 | 150 | return str(info['type'](value)) |
147 | 151 | |
148 | 152 | def _parse_query_value(self, name, info, value): |