Fix whitespace irregularities in code
[xapian.git] / xapian-core / matcher / extraweightpostlist.h
blobdc53bdf6de3a34c902169b7b1fc8740f9a1a5457
1 /** @file extraweightpostlist.h
2 * @brief add on extra weight contribution
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2001 Ananova Ltd
6 * Copyright 2003,2004,2007,2009,2011,2014 Olly Betts
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 * USA
24 #ifndef OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
25 #define OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
27 #include "multimatch.h"
28 #include "omassert.h"
30 namespace Xapian {
31 class Weight;
34 /// A postlist which adds on an extra weight contribution
35 class ExtraWeightPostList : public PostList {
36 private:
37 PostList * pl;
38 Xapian::Weight * wt;
39 MultiMatch * matcher;
40 double max_weight;
42 public:
43 Xapian::doccount get_termfreq_max() const {
44 return pl->get_termfreq_max();
46 Xapian::doccount get_termfreq_min() const {
47 return pl->get_termfreq_min();
49 Xapian::doccount get_termfreq_est() const {
50 return pl->get_termfreq_est();
53 Xapian::docid get_docid() const { return pl->get_docid(); }
55 double get_weight() const {
56 /* Second parameter of get_sumextra is number of unique terms in doc, which has been put
57 * to maintain consistency with get_sumpart, As of now none of weighting scheme is using
58 * it. Current 0 is being passed, change it to pl->get_unique_terms() in case you
59 * need access uniq_terms. */
60 double sumextra = wt->get_sumextra(pl->get_doclength(), 0);
61 AssertRel(sumextra, <=, max_weight);
62 return pl->get_weight() + sumextra;
65 double get_maxweight() const {
66 return pl->get_maxweight() + max_weight;
69 double recalc_maxweight() {
70 return pl->recalc_maxweight() + max_weight;
73 PostList *next(double w_min) {
74 PostList *p = pl->next(w_min - max_weight);
75 if (p) {
76 delete pl;
77 pl = p;
78 if (matcher) matcher->recalc_maxweight();
80 return NULL;
83 PostList *skip_to(Xapian::docid did, double w_min) {
84 PostList *p = pl->skip_to(did, w_min - max_weight);
85 if (p) {
86 delete pl;
87 pl = p;
88 if (matcher) matcher->recalc_maxweight();
90 return NULL;
93 bool at_end() const { return pl->at_end(); }
95 std::string get_description() const {
96 return "( ExtraWeight " + pl->get_description() + " )";
99 /** Return the document length of the document the current term
100 * comes from.
102 virtual Xapian::termcount get_doclength() const {
103 return pl->get_doclength();
106 virtual Xapian::termcount get_unique_terms() const {
107 return pl->get_unique_terms();
110 ExtraWeightPostList(PostList * pl_, Xapian::Weight *wt_,
111 MultiMatch *matcher_)
112 : pl(pl_), wt(wt_), matcher(matcher_),
113 max_weight(wt->get_maxextra())
116 ~ExtraWeightPostList() {
117 delete pl;
118 delete wt;
121 Xapian::termcount count_matching_subqs() const {
122 return pl->count_matching_subqs();
126 #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */