[Xapian-discuss] Setting self-defined doc ID with PHP bindings

James Aylett james-xapian at tartarus.org
Wed Feb 6 15:43:58 GMT 2008


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



More information about the Xapian-discuss mailing list