Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-12-20 12:00:07 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-12-20 12:00:07 (GMT)
commit0e682f97bf60b57d6991d52be8c0b77c5b8b5b28 (patch)
tree2cdaba534a429bc61924fac9d04b3b057965341c
parentf3d3e1ecf17aceb7cbdf29b0ef14a7c970db14f3 (diff)
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>
-rw-r--r--src/carquinyol/indexstore.py6
1 files changed, 5 insertions, 1 deletions
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):