xapian-core  1.4.26
extraweightpostlist.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2001 Ananova Ltd
6  * Copyright 2003,2004,2007,2009,2011,2014 Olly Betts
7  *
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.
12  *
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.
17  *
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
22  */
23 
24 #ifndef OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
25 #define OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
26 
27 #include "multimatch.h"
28 #include "omassert.h"
29 
30 namespace Xapian {
31  class Weight;
32 }
33 
35 class ExtraWeightPostList : public PostList {
36  private:
40  double max_weight;
41 
42  public:
44  return pl->get_termfreq_max();
45  }
47  return pl->get_termfreq_min();
48  }
50  return pl->get_termfreq_est();
51  }
52 
53  Xapian::docid get_docid() const { return pl->get_docid(); }
54 
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;
63  }
64 
65  double get_maxweight() const {
66  return pl->get_maxweight() + max_weight;
67  }
68 
69  double recalc_maxweight() {
70  return pl->recalc_maxweight() + max_weight;
71  }
72 
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();
79  }
80  return NULL;
81  }
82 
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();
89  }
90  return NULL;
91  }
92 
93  bool at_end() const { return pl->at_end(); }
94 
95  std::string get_description() const {
96  return "( ExtraWeight " + pl->get_description() + " )";
97  }
98 
103  return pl->get_doclength();
104  }
105 
107  return pl->get_unique_terms();
108  }
109 
111  MultiMatch *matcher_)
112  : pl(pl_), wt(wt_), matcher(matcher_),
113  max_weight(wt->get_maxextra())
114  { }
115 
117  delete pl;
118  delete wt;
119  }
120 
122  return pl->count_matching_subqs();
123  }
124 };
125 
126 #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
Abstract base class for postlists.
Definition: postlist.h:37
class for performing a match
virtual Xapian::docid get_docid() const =0
Return the current docid.
#define AssertRel(A, REL, B)
Definition: omassert.h:123
ExtraWeightPostList(PostList *pl_, Xapian::Weight *wt_, MultiMatch *matcher_)
virtual double get_sumextra(Xapian::termcount doclen, Xapian::termcount uniqterms) const =0
Calculate the term-independent weight component for a document.
virtual Internal * skip_to(Xapian::docid did, double w_min)=0
Skip forward to the specified docid.
virtual double recalc_maxweight()=0
Recalculate the upper bound on what get_weight() can return.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
virtual Xapian::termcount get_unique_terms() const =0
Return the number of unique terms in the current document.
A postlist which adds on an extra weight contribution.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Xapian::doccount get_termfreq_est() const
Get an estimate of the number of documents indexed by this term.
double get_weight() const
Return the weight contribution for the current position.
virtual Xapian::doccount get_termfreq_max() const =0
Get an upper bound on the number of documents indexed by this term.
virtual Xapian::doccount get_termfreq_est() const =0
Get an estimate of the number of documents indexed by this term.
virtual Xapian::doccount get_termfreq_min() const =0
Get a lower bound on the number of documents indexed by this term.
void recalc_maxweight()
Called by postlists to indicate that they&#39;ve rearranged themselves and the maxweight now possible is ...
Definition: multimatch.h:136
virtual double get_maxweight() const =0
Return an upper bound on what get_weight() can return.
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
virtual Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
virtual Xapian::termcount get_doclength() const
Return the document length of the document the current term comes from.
virtual Internal * next(double w_min)=0
Advance the current position to the next document in the postlist.
virtual Xapian::termcount get_doclength() const =0
Return the length of current document.
virtual std::string get_description() const =0
Return a string description of this object.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Xapian::docid get_docid() const
Return the current docid.
virtual Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
bool at_end() const
Return true if the current position is past the last entry in this list.
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
PostList * next(double w_min)
Advance the current position to the next document in the postlist.
Various assertion macros.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
std::string get_description() const
Return a string description of this object.
double get_maxweight() const
Return an upper bound on what get_weight() can return.
virtual double get_weight() const =0
Return the weight contribution for the current position.
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Abstract base class for weighting schemes.
Definition: weight.h:35
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.