[Xapian-discuss] Python segmentation fault when abstracting value range processor
Olly Betts
olly at survex.com
Wed Mar 4 11:30:36 GMT 2009
On Wed, Mar 04, 2009 at 11:15:06AM +0000, Simon Roe wrote:
> 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:
The solution is essentially what James said, but extended.
The key is that you need to ensure that a reference to each of the
NumberValueRangeProcessor objects is kept until the QueryParser object
is no longer needed.
(And yes, we know this isn't ideal...)
So one way to workaround this in your example (untested):
> #!/usr/bin/env python
> # encoding: utf-8
>
> import sys
> import os
> import xapian
vrps = []
> 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)
vrps.append(vrp)
> q.add_valuerangeprocessor(vrp)
>
> return q
>
> def values():
> return {1 : 'year', 2 : 'someothervalue'}
>
> if __name__ == '__main__':
>
> qp = load_queryparser()
>
> query_string = "john year:1..2"
>
> query = qp.parse_query(query_string)
>
> print "Parsed query is: %s" % query.get_description()
vrps = []
Cheers,
Olly
More information about the Xapian-discuss
mailing list