Sync arabic stemming algorithm change from Snowball
[xapian.git] / xapian-core / matcher / extraweightpostlist.cc
blob5878aa8128758169aef9c78435c1707985eaa339
1 /** @file extraweightpostlist.cc
2 * @brief PostList which adds on a term-independent weight contribution
3 */
4 /* Copyright 2017 Olly Betts
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.
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.
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
21 #include <config.h>
23 #include "extraweightpostlist.h"
25 #include "omassert.h"
26 #include "postlisttree.h"
27 #include "str.h"
29 using namespace std;
31 double
32 ExtraWeightPostList::get_weight(Xapian::termcount doclen,
33 Xapian::termcount unique_terms) const
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.
41 double sum_extra = weight->get_sumextra(doclen, unique_terms);
42 AssertRel(sum_extra,<=,max_extra);
43 return pl->get_weight(doclen, unique_terms) + sum_extra;
46 double
47 ExtraWeightPostList::recalc_maxweight()
49 return pl->recalc_maxweight() + max_extra;
52 PostList*
53 ExtraWeightPostList::next(double w_min)
55 PostList* res = pl->next(w_min - max_extra);
56 if (res) {
57 delete pl;
58 pl = res;
59 pltree->force_recalc();
61 return NULL;
64 PostList*
65 ExtraWeightPostList::skip_to(Xapian::docid, double)
67 // ExtraWeightPostList's parent will be PostListTree which doesn't
68 // call skip_to() or check().
69 Assert(false);
70 return NULL;
73 string
74 ExtraWeightPostList::get_description() const
76 string desc = "ExtraWeightPostList(";
77 desc += pl->get_description();
78 desc += ", max_extra=";
79 desc += str(max_extra);
80 desc += ')';
81 return desc;