I was just trying to figure out why a Xapian query did not work as expected, when it hit me : i was using the word ‘and’ to combine search terms, while I should be using the capitalized word ‘AND’ instead… Stupid mistake that cost me an hour to figure out. Hence this reminder
Tag Archives: Xapian
Xapian queries – a common mistake…
Installing Xapian for PHP on Linux (Debian)
Unlike installation of Xapian on OS-X for use with MAMP, the installation on Debian could not be more simple :
sudo apt-get install php5-xapian
Then restart your Apache server
sudo /etc/init.d/apache2 restart
And you’re done ![]()
Check phpinfo, there should be a section on Xapian now.
PHP, Xapian and… pointers ?
I just discovered some weird behaviour using Xapian in PHP, and I think it has something to do with pointers. I tried adding two XapianDateValueRangeProcessors as follows :
$qp->add_valuerangeprocessor(new XapianDateValueRangeProcessor(0, 'created:', true, false, 1970)); $qp->add_valuerangeprocessor(new XapianDateValueRangeProcessor(1, 'updated:', true, false, 1970));
But somehow this would break Xapian (I didn’t get any error, this script just stopped completely when parsing the query).
Read more »
Searching date ranges in Xapian and PHP
I have not much experience with Xapian, so the following post might seem trivial to some. But it took me some time to figure this out, so I might as well share my findings. After running some basic examples from the Xapian wiki (which worked out of the box), I needed to be able to search for a range of dates (e.g. date created from – to). After reading the very interesting article on the Xapian Search Architecture, I realised I needed to add a value to the document which contained the date field, opposed to the terms I had been adding. So, while indexing, I added following code :
$doc = new XapianDocument(); // some code ommitted such as adding terms, setting data, ... $doc->add_value(0, '20110101'); // some more code ommitted such as indexing the text - see examples
The first parameter defines the value slot which you want to use. This is just a number, look at it as an index of the value. You will reuse this index when searching, so it’s best to create a constant for each index regarding readability. Other than this, you create and index the document as explained in the examples.
Read more »
Using Xapian on OS-X with MAMP
I just compiled and installed Xapian on my MacBook Pro (OS-X 10.6.6) using the instructions from the Xapian installation guide. The first time I compiled Xapian, everything looked ok, but when I tried to run the extension, it appeared to be compiled in the wrong OS Architecture (64-bit, which is the default for gcc aparently, while MAMP and its PHP5 version are compiled in 32-bit). So make sure you add the CXX='g++ -m32' option when you run ./configure. If you are not sure if the extension is built in 32-bit, just check by running
file xapian.so
on the resulting xapian.so file after the build, which should result in something like this :
$ file xapian.so xapian.so: Mach-O bundle i386
Here’s the sequence for building the Xapian core and bindings (make sure you download and use the latest stable Xapian version) :
curl -O http://oligarchy.co.uk/xapian/1.1.4/xapian-core-1.1.4.tar.gz curl -O http://oligarchy.co.uk/xapian/1.1.4/xapian-bindings-1.1.4.tar.gz tar xvzf xapian-core-1.1.4.tar.gz tar xvzf xapian-bindings-1.1.4.tar.gz cd xapian-core-1.1.4 ./configure CXX='g++ -m32' make sudo make install cd .. cd xapian-bindings-1.1.4 ./configure CXX='g++ -m32' --with-php make sudo make install cd .. rm xapian-core-1.1.4.tar.gz rm xapian-bindings-1.1.4.tar.gz
This will install the PHP bindings with the default OS-X Apache and PHP version, but as I am using MAMP for my development, I will need to perform some extra steps.
Read more »
Recent Comments