[Xapian-discuss] Latest document of a database?

Robert Pollak robert.pollak@fabasoft.com
Fri, 04 Jun 2004 10:25:45 +0200


This is a multi-part message in MIME format.
--------------050000050606020607080409
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

[My mail problems continue ;) Here's the patch.]

Olly Betts wrote:
> 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.

The attached version should work (although I have not tested it with
multiplier > 1).

> It'd be nice to have this for inmemory too - it's just termlists.size()
> there.

Would you please add this if you think so? Thank you!

-- 
Robert Pollak
GPG Key ID: 748646AD

--------------050000050606020607080409
Content-Type: text/plain;
 name="lastdocids_merged.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="lastdocids_merged.patch"

Index: ChangeLog
===================================================================
RCS file: /home/rp/indexing/xapian-rpc/repository/xapian-core/ChangeLog,v
retrieving revision 1.3
diff -u -r1.3 ChangeLog
--- ChangeLog	3 Jun 2004 12:44:12 -0000	1.3
+++ ChangeLog	4 Jun 2004 07:33:59 -0000
@@ -1,3 +1,7 @@
+2004-06-04 Robert Pollak <robert.pollak@fabasoft.com>
+
+	* api/omdatabase.cc: Fixed get_lastdocid() for more than one internal database.
+
 2004-06-02 Robert Pollak <robert.pollak@fabasoft.com>
 
 	* api/omdatabase.cc, include/xapian/database.h,
Index: api/omdatabase.cc
===================================================================
RCS file: /home/rp/indexing/xapian-rpc/repository/xapian-core/api/omdatabase.cc,v
retrieving revision 1.2
diff -u -r1.2 omdatabase.cc
--- api/omdatabase.cc	3 Jun 2004 12:44:12 -0000	1.2
+++ api/omdatabase.cc	4 Jun 2004 07:57:46 -0000
@@ -231,9 +231,12 @@
 {
     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());
+
+    unsigned int multiplier = internal.size();
+    Assert(multiplier != 0);
+    for (Xapian::doccount i = 0; i < multiplier; ++i) {
+	Xapian::docid did_i = internal[i]->get_lastdocid();
+	did = std::max(did, (did_i - 1) * multiplier + i + 1); // if did_i is 0 then did is unchanged
     }
     RETURN(did);
 }

--------------050000050606020607080409--