00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_EXPANDWEIGHT_H
00022 #define XAPIAN_INCLUDED_EXPANDWEIGHT_H
00023
00024 #include <xapian/database.h>
00025
00026 #include "termlist.h"
00027
00028 #include <string>
00029 #include <vector>
00030
00031 namespace Xapian {
00032 namespace Internal {
00033
00035 class ExpandStats {
00036
00037 std::vector<bool> dbs_seen;
00038
00039
00040 Xapian::doclength avlen;
00041
00043 double expand_k;
00044
00045 public:
00047 Xapian::doccount dbsize;
00048
00050 Xapian::doccount termfreq;
00051
00053 Xapian::weight multiplier;
00054
00056 Xapian::doccount rtermfreq;
00057
00059 size_t db_index;
00060
00061 ExpandStats(Xapian::doclength avlen_, double expand_k_)
00062 : avlen(avlen_), expand_k(expand_k_),
00063 dbsize(0), termfreq(0), multiplier(0), rtermfreq(0), db_index(0) {
00064 }
00065
00066 void accumulate(Xapian::termcount wdf, Xapian::termcount doclen,
00067 Xapian::doccount subtf, Xapian::doccount subdbsize) {
00068
00069
00070 if (wdf == 0) wdf = 1;
00071
00072 multiplier += (expand_k + 1) * wdf / (expand_k * doclen / avlen + wdf);
00073 ++rtermfreq;
00074
00075
00076
00077 if (db_index >= dbs_seen.size() || !dbs_seen[db_index]) {
00078 if (db_index >= dbs_seen.size()) dbs_seen.resize(db_index + 1);
00079 dbs_seen[db_index] = true;
00080 dbsize += subdbsize;
00081 termfreq += subtf;
00082 }
00083 }
00084 };
00085
00087 class ExpandWeight {
00089 const Xapian::Database db;
00090
00092 Xapian::doccount dbsize;
00093
00095 Xapian::doclength avlen;
00096
00098 Xapian::doccount rsize;
00099
00110 bool use_exact_termfreq;
00111
00113 double expand_k;
00114
00115 public:
00126 ExpandWeight(const Xapian::Database &db_,
00127 Xapian::doccount rsize_,
00128 bool use_exact_termfreq_,
00129 double expand_k_)
00130 : db(db_), dbsize(db.get_doccount()), avlen(db.get_avlength()),
00131 rsize(rsize_), use_exact_termfreq(use_exact_termfreq_),
00132 expand_k(expand_k_) { }
00133
00139 Xapian::weight get_weight(TermList * merger,
00140 const std::string & term) const;
00141 };
00142
00143 }
00144 }
00145
00146 #endif // XAPIAN_INCLUDED_EXPANDWEIGHT_H