[Xapian-discuss] Re: searching and sorting by date

Michel Pelletier michel at dialnetwork.com
Thu Mar 23 18:28:23 GMT 2006


> If you use the bindings, it's likely that more people on this list
> will be able to help. If there's useful stuff we can put into the
> bindings to make it more Python like, we can do that - we already have
> the MSet (and similar) behave as a Python iterator so you can do:

Sorry if my last msg sounds a little frustrated, I do appreciate all the 
help a lot and I forgot to address this paragraph.

I think there are a couple of "pythonic" idioms that would be useful but 
I don't see their purpose being added to the SWIG'ed API, rather they 
should be in a seperate module distributed with the xapian bindings that 
did some of the tedious backwork, like mapping names to value slots, 
providing ways to query the db in one shot instead of constantly 
retyping the pattern "e=Enquire(d).set_query(Query(QueryParser(...)))" 
and some simple classes that make it easy to create documents and terms 
and index them.

These features are exactly what xapwrap provides, although at some cost 
of magical hackery and obfuscation, but from what I can see in the code 
most of that obfuscation is an attempt to remove tedious bookeeping 
needed to use the SWIG api.  Through its philosophy and design python 
programmers largely don't expect the have to manage lots of bookkeeping 
and conventions to use a library, those pedestrian tasks are something 
that that library (or a high level wrapper library) should provide. 
This is a common pattern in Python, to have a low level library (like 
_thread.so) wrapped by a higher level library ("threading"), relational 
database modules in Python almost always take this pattern.

So while I understand the suggestions from some on this list to not use 
Xapwrap and instead use the SWIG bindings, I know for a fact that if I 
did that I'd just end up writing a bunch of code that does essentially 
what Xapwrap does, manages names for prefixes, sets common query and 
parser options, defines classes for common entities, etc.  So that I can 
just say:

d = Document(TextField("foo bar bang"), Keyword("genre", "punk"))
idx.index(d)
for result in idx.search("foo genre:punk"):
   print result

I don't see how I can get that much bang per line out of the swig 
wrappers without essentially writing my own Xapwrap-like library, and I 
don't see how anyone else can do it without them all writing their own 
slightly similar/different versions of their own little library.  This 
makes me think the need for Xapwrap is genuine and that it is bringing 
me and others benefits that the swig API doesn't provide.

Of course I'm not trying to insult the SWIG API or offend anyone's 
sensibilities.  The swig API is pefectly suited for low-level, 
cross-language, direct use of xapian, I just think there exist high 
level use cases that they don't provide that a high level wrapper module 
should.

-Michel




More information about the Xapian-discuss mailing list