[Xapian-discuss] FYI: PHP5 Gotcha

Mike Boone boonedocks at gmail.com
Wed Dec 12 03:33:58 GMT 2007


In converting my old Xapian code from pre-1.0 and PHP4 to 1.0 4 and
PHP5, I ran into a problem which took me a while to debug. So I
thought I'd post about it here just in case anyone goes looking.

The problem: replaced and deleted Xapian documents were not being
properly replaced and deleted.

The solution: The Xapian::WritableDatabase::replace_document and
Xapian::WritableDatabase::delete_document methods are overloaded...you
can either submit a numeric value of the Xapian document ID or a
string for a term which affect all the documents containing that term.
I was grabbing my Xapian document ID from a MySQL database, which came
back to PHP as a string. So passing that string of the Xapian document
ID to the replace/delete methods was inadvertently being handled as a
term. If I used the PHP function intval() on the Xapian document ID
string, it works properly.

For example:

$strXapID='1234';
$xapWritableDB->delete_document(intval($strXapID));

Since PHP is normally loosely typed, this distinction was hard to
track down. Hope this post saves time/trouble for other users.

Mike Boone.
http://boonedocks.net/mike/



More information about the Xapian-discuss mailing list