2 * @brief add on extra weight contribution
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
24 #ifndef OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
25 #define OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
27 #include "multimatch.h"
34 /// A postlist which adds on an extra weight contribution
35 class ExtraWeightPostList
: public PostList
{
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
);
78 if (matcher
) matcher
->recalc_maxweight();
83 PostList
*skip_to(Xapian::docid did
, double w_min
) {
84 PostList
*p
= pl
->skip_to(did
, w_min
- max_weight
);
88 if (matcher
) matcher
->recalc_maxweight();
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
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() {
121 Xapian::termcount
count_matching_subqs() const {
122 return pl
->count_matching_subqs();
126 #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */