[Xapian-discuss] Python segmentation fault when abstracting value range processor
Simon Roe
simon.roe at talusdesign.co.uk
Wed Mar 4 11:15:06 GMT 2009
On Wed, Mar 4, 2009 at 11:05 AM, James Aylett <james-xapian at tartarus.org> wrote:
> On Wed, Mar 04, 2009 at 10:56:17AM +0000, Simon Roe wrote:
>> def load_queryparser():
>> q = xapian.QueryParser()
>> q.set_default_op(xapian.Query.OP_AND)
>>
>> vrp = xapian.NumberValueRangeProcessor(1,'year:')
>> q.add_valuerangeprocessor(vrp)
>>
>> return q
>
> vrp will be deleted by the python layer. This perhaps isn't what we
> want, but is what is happening right now. You can make this work by
> returning (q, vrp) and assigning the tuple to (qp, vrp) in the rest of
> the code.
>
> Verified with something reasonably trunky (Richard's geo branch from
> around the start of the year is what I have installed on my dev
> machine, it seems). ISTR that we have a way of tackling this kind of
> problem, but I could be misremembering. If no one else pipes up, I'll
> add it to trac.
Thanks, this worked, however it doesn't solve my first problem. What
I'm actually trying to do is add a load of values, read in from a dict
of values. This error came about when doing that, so I simplified the
code, however the code below is really what I'm trying to do:
====================================
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
import xapian
def load_queryparser():
q = xapian.QueryParser()
q.set_default_op(xapian.Query.OP_AND)
for k,v in values().items():
print k,v
vrp = xapian.NumberValueRangeProcessor(k,v)
q.add_valuerangeprocessor(vrp)
return q
def values():
return {1 : 'year', 2 : 'someothervalue'}
if __name__ == '__main__':
qp = load_queryparser()
# This works fine
# qp = xapian.QueryParser()
# qp.set_default_op(xapian.Query.OP_AND)
#
# vrp = xapian.NumberValueRangeProcessor(1,'year:')
# qp.add_valuerangeprocessor(vrp)
query_string = "john year:1..2"
query = qp.parse_query(query_string)
print "Parsed query is: %s" % query.get_description()
====================================
--
Help save the economy:
http://seriouschange.org.uk/
E: simon.roe at talusdesign.co.uk
M: 07742079314
More information about the Xapian-discuss
mailing list