Index: matcher/bm25weight.cc
===================================================================
--- matcher/bm25weight.cc	(revision 9600)
+++ matcher/bm25weight.cc	(working copy)
@@ -153,6 +153,8 @@
 BM25Weight::get_sumextra(Xapian::doclength len) const
 {
     DEBUGCALL(MATCH, Xapian::weight, "BM25Weight::get_sumextra", len);
+    if (!weight_calculated) calc_termweight();
+
     Xapian::doclength normlen = len * lenpart;
     if (normlen < min_normlen) normlen = min_normlen;
     Xapian::weight extra = 2 * k2 * querysize / (1 + normlen);
@@ -172,6 +174,7 @@
 }
 
 bool BM25Weight::get_sumpart_needs_doclength() const {
+    if (!weight_calculated) calc_termweight();
     return (b != 0 && k1 != 0 && lenpart != 0);
 }
 
Index: common/stats.h
===================================================================
--- common/stats.h	(revision 9600)
+++ common/stats.h	(working copy)
@@ -348,6 +348,8 @@
 inline Xapian::doccount
 Xapian::Weight::Internal::get_total_termfreq(const string & tname) const
 {
+    // We pass an empty string for tname when calculating the extra weight.
+    if (tname.empty()) return 0;
     if (total_stats == 0) perform_request();
 
     // To get the statistics about a given term, we have to have
@@ -363,6 +365,8 @@
 inline Xapian::doccount
 Xapian::Weight::Internal::get_total_reltermfreq(const string & tname) const
 {
+    // We pass an empty string for tname when calculating the extra weight.
+    if (tname.empty()) return 0;
     if (total_stats == 0) perform_request();
     std::map<string, Xapian::doccount>::const_iterator rtfreq;
     rtfreq = total_stats->reltermfreq.find(tname);
