Ticket #1342: 0001-use-xapian.sortable_serialise-for-storing-searching-.patch

File 0001-use-xapian.sortable_serialise-for-storing-searching-.patch, 2.1 KB (added by sascha_silbe, 15 years ago)

use xapian.sortable_serialise() for storing/searching numeric values

  • src/carquinyol/indexstore.py

    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 b _QUERY_VALUE_MAP = { 
    6363class TermGenerator (xapian.TermGenerator):
    6464
    6565    def index_document(self, document, properties):
    66         document.add_value(_VALUE_TIMESTAMP, str(properties['timestamp']))
     66        document.add_value(_VALUE_TIMESTAMP, xapian.sortable_serialise(properties['timestamp']))
    6767        document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
    6868
    6969        self.set_document(document)
    class QueryParser (xapian.QueryParser): 
    139139                'Did you mean to pass a list instead?')
    140140
    141141        start, end = value
     142        if isinstance(start, (float, int, long)):
     143            return Query(Query.OP_VALUE_RANGE, value_no,
     144                xapian.sortable_serialise(start),
     145                xapian.sortable_serialise(end))
     146
    142147        return Query(Query.OP_VALUE_RANGE, value_no, str(start), str(end))
    143148
    144149    def _parse_query_value(self, name, value_no, value):
    class QueryParser (xapian.QueryParser): 
    156161            end = value.get('end', sys.maxint)
    157162            return self._parse_query_value_range(name, (start, end), value_no)
    158163
     164        elif isinstance(value, (float, int, long)):
     165            return Query(Query.OP_VALUE_RANGE, value_no,
     166                xapian.sortable_serialise(value),
     167                xapian.sortable_serialise(value))
     168
    159169        else:
    160             return Query(Query.OP_VALUE_RANGE,
    161                 _QUERY_VALUE_MAP[name], str(value), str(value))
     170            return Query(Query.OP_VALUE_RANGE, value_no, str(value),
     171                str(value))
    162172
    163173    def _parse_query_xapian(self, query_str):
    164174        try: