Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-core / api / leafpostlist.h
blob2c712f3fea97f582e04c33a34565265b633ba47b
1 /** @file leafpostlist.h
2 * @brief Abstract base class for leaf postlists.
3 */
4 /* Copyright (C) 2007,2009,2011,2013,2015 Olly Betts
5 * Copyright (C) 2009 Lemur Consulting Ltd
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.
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.
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
22 #ifndef XAPIAN_INCLUDED_LEAFPOSTLIST_H
23 #define XAPIAN_INCLUDED_LEAFPOSTLIST_H
25 #include "postlist.h"
27 #include <string>
29 namespace Xapian {
30 class Weight;
33 /** Abstract base class for leaf postlists.
35 * This class provides the following features in addition to the PostList
36 * class:
38 class LeafPostList : public PostList {
39 /// Don't allow assignment.
40 void operator=(const LeafPostList &);
42 /// Don't allow copying.
43 LeafPostList(const LeafPostList &);
45 protected:
46 const Xapian::Weight * weight;
48 bool need_doclength, need_unique_terms;
50 /// The term name for this postlist (empty for an alldocs postlist).
51 std::string term;
53 /// Only constructable as a base class for derived classes.
54 explicit LeafPostList(const std::string & term_)
55 : weight(0), need_doclength(false), need_unique_terms(false),
56 term(term_) { }
58 public:
59 ~LeafPostList();
61 /** Set the weighting scheme to use during matching.
63 * If this isn't called, get_weight() and get_maxweight() will both
64 * return 0.
66 * You should not call this more than once on a particular object.
68 * @param weight_ The weighting object to use. Must not be NULL.
70 void set_termweight(const Xapian::Weight * weight_);
72 double resolve_lazy_termweight(Xapian::Weight * weight_,
73 Xapian::Weight::Internal * stats,
74 Xapian::termcount qlen,
75 Xapian::termcount wqf,
76 double factor)
78 weight_->init_(*stats, qlen, term, wqf, factor);
79 // There should be an existing LazyWeight set already.
80 Assert(weight);
81 const Xapian::Weight * const_weight_ = weight_;
82 swap(weight, const_weight_);
83 delete const_weight_;
84 need_doclength = weight->get_sumpart_needs_doclength_();
85 stats->termfreqs[term].max_part += weight->get_maxpart();
86 return stats->termfreqs[term].max_part;
89 /** Return the exact term frequency.
91 * Leaf postlists have an exact termfreq, which get_termfreq_min(),
92 * get_termfreq_max(), and get_termfreq_est() all report.
94 virtual Xapian::doccount get_termfreq() const = 0;
96 Xapian::doccount get_termfreq_min() const;
97 Xapian::doccount get_termfreq_max() const;
98 Xapian::doccount get_termfreq_est() const;
100 double get_maxweight() const;
101 double get_weight() const;
102 double recalc_maxweight();
104 TermFreqs get_termfreq_est_using_stats(
105 const Xapian::Weight::Internal & stats) const;
107 Xapian::termcount count_matching_subqs() const;
109 /** Open another postlist from the same database.
111 * @param term_ The term to open a postlist for. If term_ is near to
112 * this postlist's term, then this can be a lot more
113 * efficient (and if it isn't very near, there's not
114 * much of a penalty). Using this method can make a
115 * wildcard expansion much more memory efficient.
117 * @return The new postlist object, or NULL if not supported
118 * (in which case the caller should probably the postlist
119 * via the database instead).
121 virtual LeafPostList * open_nearby_postlist(const std::string & term_) const;
124 #endif // XAPIAN_INCLUDED_LEAFPOSTLIST_H