Ticket #1342: 1342.patch

File 1342.patch, 1.8 KB (added by sascha_silbe, 14 years ago)

fix range query for timestamp to do numerical comparison instead of lexical

  • src/carquinyol/indexstore.py

    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 = { 
    6363class TermGenerator (xapian.TermGenerator):
    6565    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'])))
    6768        document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
    6970        self.set_document(document)
    class QueryParser (xapian.QueryParser): 
    143144            self._convert_value(info, start), self._convert_value(info, end))
    145146    def _convert_value(self, info, value):
     147        if info['type'] in (float, int, long):
     148            return xapian.sortable_serialise(info['type'](value))
    146150        return str(info['type'](value))
    148152    def _parse_query_value(self, name, info, value):