[Xapian-devel] Document ID 0 is invalid... but not always...
Daniel Ménard
Daniel.Menard at bdsp.tm.fr
Tue May 15 12:30:12 BST 2007
Note: this is rather long and not very important and I don't want to
prevent the team from releasing version 1.0, so go on reading only if
you have too much free time !!! ;-)
0 is not a valid document ID, never, ever, but I just found a special
case in which xapian will create a record and return 0 for the newly
created record.
In fact, I was "hacking", trying to store metadata in a "special" record
with docId "-1"...
I know, this is bad, but what is interesting is what xapian does in such
a situation...
Here is a simple PHP test :
$db=new XapianWritableDatabase('pathtodb',
Xapian::DB_CREATE_OR_OVERWRITE);
$doc=new XapianDocument();
$doc->set_data('metadata'); // waiting for
http://www.xapian.org/cgi-bin/bugzilla/show_bug.cgi?id=143
$doc->add_term('metadata');
$db->replace_document(-1, $doc); // or 4294967295 = (2^32)-1
$doc=new XapianDocument();
$doc->set_data('data');
$doc->add_term('data');
$docId=$db->add_document($doc); // get_lastdocid()+1 overflows, will
return 0
echo "doc #$docId added\n";
The two docs are added without error, but the second one will get the
docId 0 and of course won't be accessible.
Another variant will cause xapian to overwrite an existing record :
(pseudo code) :
new XapianWritableDatabase()
add_document($doc); // will get id #1
replace_document(-1, $doc);
add_document($doc); // will get id #0
add_document($doc); // will again get id #1, previous record is
probably overwritten
As I said at the beginning, I don't think this is very important, and it
does not cause me any inconvenience.
I just thought it would be better to let you know.
Thanks for reading, please go back releasing xapian 1.0 !
--
Daniel Ménard
More information about the Xapian-devel
mailing list