Yannick Warnier
2008-Feb-06 15:34 UTC
[Xapian-discuss] Setting self-defined doc ID with PHP bindings
Hello, I've finally started playing with Xapian in a small test application designed with CakePHP, so I've also started running into small practical problems. I would like to have a one-to-one relationship between a document indexed in Xapian and a database table containing the full list of documents (and details about them to access them from inside my web application). I've found some comments about that dating from some time ago, saying that one should use the XapianWritableDatabase::replace_document() method rather than the XapianWritableDatabase::add_document(), so that I can add the document ID myself (being numeric and auto-incremented, I don't suppose that would create a problem, would it?) However, if that seems to work well (I get no error message), I have no idea how to check if my document was indexed using the right ID (is there some command-line tool to check the list of documents in my database?). Also, there seems to be no way (as far as the PHP bindings are concerned) to get this document ID back from search results. I actually do get search results, but the PHP print_r() function isn't very helpful with the contents of an mset or one document out of an mset, as it always give me a "Resource" output. I have tried a $mset->get_document()->get_data(); and a $mset->get_document()->get_docid(); but neither of these seem to work. Could someone hint me to the right way of doing this please? (and possibly answer the side-questions as well) Thanks, Yannick
James Aylett
2008-Feb-06 15:43 UTC
[Xapian-discuss] Setting self-defined doc ID with PHP bindings
On Wed, Feb 06, 2008 at 10:34:38AM -0500, Yannick Warnier wrote:> I've found some comments about that dating from some time ago, saying > that one should use the XapianWritableDatabase::replace_document() > method rather than the XapianWritableDatabase::add_document(), so that I > can add the document ID myself (being numeric and auto-incremented, I > don't suppose that would create a problem, would it?)It shouldn't do, no. You'll start getting issues if you need to move to multiple databases, or something else more complex, but for now you should be fine.> However, if that seems to work well (I get no error message), I have no > idea how to check if my document was indexed using the right ID (is > there some command-line tool to check the list of documents in my > database?).If you use replace_document(), it will be indexed with the right ID. To get a list of docids, probably the quickest thing is to write a quick PHP script to check $db->get_document(docid) for all docids you care about. $db->get_lastdocid() and $db->get_doccount() will help here.> Also, there seems to be no way (as far as the PHP bindings are > concerned) to get this document ID back from search results. I actually > do get search results, but the PHP print_r() function isn't very helpful > with the contents of an mset or one document out of an mset, as it > always give me a "Resource" output. > > I have tried a > $mset->get_document()->get_data(); > and a > $mset->get_document()->get_docid(); > but neither of these seem to work.Try $mset->get_docid(). $mset->get_document()->get_data() will return whatever you put in there in the first place (using $doc->set_data()), so my guess is you aren't putting anything there at all right now. For your application you may not have a use for it. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james at tartarus.org uncertaintydivision.org