From 2ccb431449c2e32c5af7d82778ec8a1651a51ea6 Mon Sep 17 00:00:00 2001
From: Sascha Silbe <sascha@silbe.org>
Date: Sun, 13 Sep 2009 23:59:20 +0200
Subject: [PATCH] use xapian.sortable_serialise() for storing/searching numeric values (#1342)

---
 src/carquinyol/indexstore.py |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 6a70aee..057eb79 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -63,7 +63,7 @@ _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(properties['timestamp']))
         document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
 
         self.set_document(document)
@@ -139,6 +139,11 @@ class QueryParser (xapian.QueryParser):
                 'Did you mean to pass a list instead?')
 
         start, end = value
+        if isinstance(start, (float, int, long)):
+            return Query(Query.OP_VALUE_RANGE, value_no,
+                xapian.sortable_serialise(start),
+                xapian.sortable_serialise(end))
+
         return Query(Query.OP_VALUE_RANGE, value_no, str(start), str(end))
 
     def _parse_query_value(self, name, value_no, value):
@@ -156,9 +161,14 @@ class QueryParser (xapian.QueryParser):
             end = value.get('end', sys.maxint)
             return self._parse_query_value_range(name, (start, end), value_no)
 
+        elif isinstance(value, (float, int, long)):
+            return Query(Query.OP_VALUE_RANGE, value_no,
+                xapian.sortable_serialise(value),
+                xapian.sortable_serialise(value))
+
         else:
-            return Query(Query.OP_VALUE_RANGE,
-                _QUERY_VALUE_MAP[name], str(value), str(value))
+            return Query(Query.OP_VALUE_RANGE, value_no, str(value),
+                str(value))
 
     def _parse_query_xapian(self, query_str):
         try:
-- 
1.6.3.3

