Branch data Line data Source code
1 : : /** @file extraweightpostlist.cc
2 : : * @brief PostList which adds on a term-independent weight contribution
3 : : */
4 : : /* Copyright 2017 Olly Betts
5 : : *
6 : : * This program is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU General Public License as
8 : : * published by the Free Software Foundation; either version 2 of the
9 : : * License, or (at your option) any later version.
10 : : *
11 : : * This program is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program; if not, write to the Free Software
18 : : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : : */
20 : :
21 : : #include <config.h>
22 : :
23 : : #include "extraweightpostlist.h"
24 : :
25 : : #include "omassert.h"
26 : : #include "postlisttree.h"
27 : : #include "str.h"
28 : :
29 : : using namespace std;
30 : :
31 : : double
32 : 2125 : ExtraWeightPostList::get_weight(Xapian::termcount doclen,
33 : : Xapian::termcount unique_terms) const
34 : : {
35 : : /* Weight::get_sumextra() takes two parameters (document length and number
36 : : * of unique terms) but none of the currently implemented weighting schemes
37 : : * actually use the latter - it was added because it's likely to be wanted
38 : : * at some point, and so that we got all the incompatible changes needed to
39 : : * add support for the number of unique terms over with in one go.
40 : : */
41 : 2125 : double sum_extra = weight->get_sumextra(doclen, unique_terms);
42 : : AssertRel(sum_extra,<=,max_extra);
43 : 2125 : return pl->get_weight(doclen, unique_terms) + sum_extra;
44 : : }
45 : :
46 : : double
47 : 1334 : ExtraWeightPostList::recalc_maxweight()
48 : : {
49 : 1334 : return pl->recalc_maxweight() + max_extra;
50 : : }
51 : :
52 : : PostList*
53 : 3459 : ExtraWeightPostList::next(double w_min)
54 : : {
55 : 3459 : PostList* res = pl->next(w_min - max_extra);
56 [ + + ]: 3459 : if (res) {
57 [ + - ]: 422 : delete pl;
58 : 422 : pl = res;
59 : 422 : pltree->force_recalc();
60 : : }
61 : 3459 : return NULL;
62 : : }
63 : :
64 : : PostList*
65 : 0 : ExtraWeightPostList::skip_to(Xapian::docid, double)
66 : : {
67 : : // ExtraWeightPostList's parent will be PostListTree which doesn't
68 : : // call skip_to() or check().
69 : : Assert(false);
70 : 0 : return NULL;
71 : : }
72 : :
73 : : string
74 : 0 : ExtraWeightPostList::get_description() const
75 : : {
76 [ # # ]: 0 : string desc = "ExtraWeightPostList(";
77 [ # # ][ # # ]: 0 : desc += pl->get_description();
78 [ # # ]: 0 : desc += ", max_extra=";
79 [ # # ][ # # ]: 0 : desc += str(max_extra);
80 [ # # ]: 0 : desc += ')';
81 : 0 : return desc;
82 : : }
|