[Xapian-discuss] Latest document of a database?
Olly Betts
olly@survex.com
Thu, 3 Jun 2004 15:16:34 +0100
On Thu, Jun 03, 2004 at 03:02:00PM +0200, Robert Pollak wrote:
> here is a patch that defines Database::get_lastdocid() for the quartz
> backend.
Thanks.
> I also had to call Database::remove/add instead of replace_document, to
> always get the most recently added doc. (replace reuses the docid.)
That's by design. If you want a new docid, remove/add is the way to do
it.
> --- api/omdatabase.cc 15 Apr 2004 08:54:05 -0000 1.1.1.1
> +++ api/omdatabase.cc 3 Jun 2004 09:24:34 -0000
> @@ -226,6 +226,18 @@
> RETURN(docs);
> }
>
> +Xapian::docid
> +Database::get_lastdocid() const
> +{
> + DEBUGAPICALL(Xapian::docid, "Database::get_lastdocid", "");
> + Xapian::docid did = 0;
> + vector<Xapian::Internal::RefCntPtr<Database::Internal> >::const_iterator i;
> + for (i = internal.begin(); i != internal.end(); ++i) {
> + did = std::max(did, (*i)->get_lastdocid());
> + }
> + RETURN(did);
> +}
> +
> Xapian::doclength
> Database::get_avlength() const
> {
This part isn't correct - the document ids are interleaved, so you need
to convert (*i)->get_lastdocid() to give the docid in the combined
database.
It'd be nice to have this for inmemory too - it's just termlists.size()
there.
I can fix those up (but don't let me stop you if you want to...)
Cheers,
Olly