xapian-core  2.0.0
extraweightpostlist.cc
Go to the documentation of this file.
1 
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, see
18  * <https://www.gnu.org/licenses/>.
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
33  Xapian::termcount unique_terms,
34  Xapian ::termcount wdfdocmax) const
35 {
36  /* Weight::get_sumextra() takes three parameters (document length, number of
37  * unique terms and the max wdf in the document) but currently only doclen
38  * is actually used - unique_terms and wdfdocmax were added because they are
39  * likely to be wanted at some point, and so that we got all the
40  * incompatible changes needed to add support for the unique terms and max
41  * wdf over with in one go.
42  */
43  double sum_extra = weight->get_sumextra(doclen, unique_terms, wdfdocmax);
44  AssertRel(sum_extra,<=,max_extra);
45  return pl->get_weight(doclen, unique_terms, wdfdocmax) + sum_extra;
46 }
47 
48 double
50 {
51  return pl->recalc_maxweight() + max_extra;
52 }
53 
54 PostList*
56 {
57  PostList* res = pl->next(w_min - max_extra);
58  if (res) {
59  delete pl;
60  pl = res;
61  pltree->force_recalc();
62  }
63  return NULL;
64 }
65 
66 PostList*
68 {
69  // ExtraWeightPostList's parent will be PostListTree which doesn't
70  // call skip_to() or check().
71  Assert(false);
72  return NULL;
73 }
74 
75 string
77 {
78  string desc = "ExtraWeightPostList(";
79  desc += pl->get_description();
80  desc += ", max_extra=";
81  desc += str(max_extra);
82  desc += ')';
83  return desc;
84 }
PostList * skip_to(Xapian::docid, double w_min)
Skip forward to the specified docid.
std::string get_description() const
Return a string description of this object.
double get_weight(Xapian::termcount doclen, Xapian::termcount unique_terms, Xapian::termcount wdfdocmax) const
Return the weight contribution for the current position.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
Abstract base class for postlists.
Definition: postlist.h:40
virtual PostList * next(double w_min)=0
Advance the current position to the next document in the postlist.
PostList * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:168
PostList which adds on a term-independent weight contribution.
string str(int value)
Convert int to std::string.
Definition: str.cc:91
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
#define AssertRel(A, REL, B)
Definition: omassert.h:123
#define Assert(COND)
Definition: omassert.h:122
Class for managing a tree of PostList objects.
Convert types to std::string.