xapian-core  1.4.26
leafpostlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2013,2015,2016,2020 Olly Betts
5  * Copyright (C) 2009 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_LEAFPOSTLIST_H
23 #define XAPIAN_INCLUDED_LEAFPOSTLIST_H
24 
25 #include "postlist.h"
26 
27 #include <algorithm>
28 #include <string>
29 
30 namespace Xapian {
31  class Weight;
32 }
33 
39 class LeafPostList : public PostList {
41  void operator=(const LeafPostList &);
42 
44  LeafPostList(const LeafPostList &);
45 
46  protected:
48 
49  bool need_doclength, need_unique_terms;
50 
52  std::string term;
53 
55  explicit LeafPostList(const std::string & term_)
56  : weight(0), need_doclength(false), need_unique_terms(false),
57  term(term_) { }
58 
59  public:
60  ~LeafPostList();
61 
71  void set_termweight(const Xapian::Weight * weight_);
72 
75  Xapian::termcount qlen,
77  double factor)
78  {
79  weight_->init_(*stats, qlen, term, wqf, factor, this);
80  // There should be an existing LazyWeight set already.
81  Assert(weight);
82  const Xapian::Weight * const_weight_ = weight_;
83  std::swap(weight, const_weight_);
84  delete const_weight_;
85  need_doclength = weight->get_sumpart_needs_doclength_();
86  // We get such terms from the database so they should exist.
87  Assert(get_termfreq() > 0);
88  double result = weight->get_maxpart();
89  double& max_part = stats->termfreqs[term].max_part;
90  max_part = std::max(max_part, result);
91  return result;
92  }
93 
99  virtual Xapian::doccount get_termfreq() const = 0;
100 
101  Xapian::doccount get_termfreq_min() const;
102  Xapian::doccount get_termfreq_max() const;
103  Xapian::doccount get_termfreq_est() const;
104 
105  double get_maxweight() const;
106  double get_weight() const;
107  double recalc_maxweight();
108 
109  TermFreqs get_termfreq_est_using_stats(
110  const Xapian::Weight::Internal & stats) const;
111 
112  Xapian::termcount count_matching_subqs() const;
113 
114  void gather_position_lists(OrPositionList* orposlist);
115 
128  virtual LeafPostList * open_nearby_postlist(const std::string & term_) const;
129 
130  virtual Xapian::termcount get_wdf_upper_bound() const = 0;
131 
139  void set_term(const std::string & term_) { term = term_; }
140 };
141 
142 #endif // XAPIAN_INCLUDED_LEAFPOSTLIST_H
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.
Definition: postlist.h:37
double resolve_lazy_termweight(Xapian::Weight *weight_, Xapian::Weight::Internal *stats, Xapian::termcount qlen, Xapian::termcount wqf, double factor)
Definition: leafpostlist.h:73
const Xapian::Weight * weight
Definition: leafpostlist.h:47
Abstract base class for leaf postlists.
Definition: leafpostlist.h:39
std::string term
The term name for this postlist (empty for an alldocs postlist).
Definition: leafpostlist.h:52
#define false
Definition: header.h:9
Abstract base class for postlists.
bool get_sumpart_needs_doclength_() const
Definition: weight.h:333
std::map< std::string, TermFreqs > termfreqs
Map of term frequencies and relevant term frequencies for the collection.
virtual double get_maxpart() const =0
Return an upper bound on what get_sumpart() can return for any document.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
void init_(const Internal &stats, Xapian::termcount query_len_, const std::string &term, Xapian::termcount wqf_, double factor)
Definition: weight.cc:93
Class to hold statistics for a given collection.
LeafPostList(const std::string &term_)
Only constructable as a base class for derived classes.
Definition: leafpostlist.h:55
The frequencies for a term.
void set_term(const std::string &term_)
Set the term name.
Definition: leafpostlist.h:139
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
bool need_unique_terms
Definition: leafpostlist.h:49
Abstract base class for weighting schemes.
Definition: weight.h:35