[Xapian-discuss] C++ PostingSource with Python bindings

Jason Tackaberry tack at urandom.ca
Sat Sep 1 01:23:06 BST 2012


Hi all,

I want to use a custom PostingSource to adjust weightings of my search 
results, but an implementation in Python is proving to be very slow for 
large result sets.  So I'm looking to write the custom PostingSource in C++.

The basic strategy would be:

q = xapian.Query(...)
q = mycustommodule.add_posting_source(q)


I can acquire the Query pointer easily enough (it's just int(q.this)) 
and cast that to Xapian::Query, and then construct a new Xapian::Query 
with the custom posting source mixed in with OP_AND_MAYBE.

The challenge is getting the new C++ query object back into Python 
space.  SWIG documents say that although int(swigobj) gives you the 
underlying pointer, the inverse operation of constructing a SWIG object 
from a pointer isn't possible. [1]  I'm hoping there might be some 
Xapian-specific way, or that this documented limitation doesn't apply to 
native C/C++ code.

Is there a solution, or some alternative approach?

Thanks,
Jason.

[1] http://www.swig.org/Doc2.0/Python.html#Python_nn18



More information about the Xapian-discuss mailing list