00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <config.h>
00025
00026 #include "database.h"
00027 #include "rset.h"
00028 #include "stats.h"
00029 #include "omdebug.h"
00030
00031 #include "autoptr.h"
00032 #include "termlist.h"
00033
00034 void
00035 RSetI::calculate_stats()
00036 {
00037 DEBUGCALL(MATCH, void, "RSetI::calculate_stats", "");
00038 Assert(!calculated_reltermfreqs);
00039 std::set<Xapian::docid>::const_iterator doc;
00040 for (doc = documents.begin(); doc != documents.end(); doc++) {
00041 DEBUGLINE(WTCALC, "Counting reltermfreqs in document " << *doc << " [ ");
00042 if (dbroot) {
00043 AutoPtr<TermList> tl(dbroot->open_term_list(*doc));
00044 tl->next();
00045 while (!tl->at_end()) {
00046
00047
00048
00049 string tname = tl->get_termname();
00050 if (reltermfreqs.find(tname) != reltermfreqs.end()) {
00051 reltermfreqs[tname] ++;
00052 DEBUGLINE(WTCALC, tname << " now has reltermfreq of " << reltermfreqs[tname]);
00053 }
00054 tl->next();
00055 }
00056 } else {
00057 Xapian::TermIterator tl = root.termlist_begin(*doc);
00058 Xapian::TermIterator tlend = root.termlist_end(*doc);
00059 while (tl != tlend) {
00060
00061
00062
00063 string tname = *tl;
00064 if (reltermfreqs.find(tname) != reltermfreqs.end()) {
00065 reltermfreqs[tname] ++;
00066 DEBUGLINE(WTCALC, tname << " now has reltermfreq of " << reltermfreqs[tname]);
00067 }
00068 tl++;
00069 }
00070 }
00071 DEBUGLINE(WTCALC, "] ");
00072 }
00073 calculated_reltermfreqs = true;
00074 }
00075
00076 void
00077 RSetI::contribute_stats(Stats & stats)
00078 {
00079 DEBUGCALL(MATCH, void, "RSetI::contribute_stats", stats);
00080 calculate_stats();
00081
00082 std::map<string, Xapian::doccount>::const_iterator i;
00083 for (i = reltermfreqs.begin(); i != reltermfreqs.end(); i++) {
00084 stats.set_reltermfreq(i->first, i->second);
00085 }
00086 stats.rset_size += get_rsize();
00087 }