Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Fry-IT

Fry-IT is the company I work for

Photos

Photoalbum, both old and new.

Zope

What I have and am doing with Zope

Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me

My contact details and how to contact me.

 

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 

Tip: creating a Xapian database in Python


test runner, databaseopeningerror, mkdir, xapian, writabledatabase

18th of January 2010

This cost me some hair-pulling today as I was trying to write a custom test runner for a Django project I'm working on that creates a test Xapian database just for running the tests. Basically, you can't do this:

 os.mkdir(database_file_path)

Because if you do you end up getting these strange DatabaseOpeningError exceptions. So, here's how you do it:

 import xapian
 xapian.WritableDatabase(database_file_path,
                         xapian.DB_CREATE_OR_OPEN)

Hopefully by blogging about this some other poor coder will save some time.



Comment

LE - 19th January 2010  [«« Reply to this]
Why would you mkdir a database's directory? Makes no sense.
Peter Bengtsson - 19th January 2010   [«« Reply to this]
Because the test runner doesn't work like a normal Django startup. Without first doing this, the first test that tries to open the database in read-only mode will fail. Perhaps there is a more appropriate way but I couldn't immediately find one.
david - 19th January 2010  [«« Reply to this]
I normally use xappy for xapian stuff, it makes it a lot easier, or at least I look at the source code if there is something that is bugging me. i.e http://code.google.com/p/xappy/source/browse/trunk/xappy/indexerconnection.py";

The makers of it also make xapian core, so xappy has got best use practices in it.
Peter Bengtsson - 19th January 2010   [«« Reply to this]
I'm currently using django-haystack to wrap Xapian. django-haystack actually wraps xapian-haystack.

I might reconsider this because I'm not getting the most out of django-haystack because so much of my work has been to patch and subclass django-haystack in various forms because I'm not using Django's ORM.

I will take a closer look at xappy as it might actually simplify the stack in this project.
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.