1 /** @file leafpostlist.h
2 * @brief Abstract base class for leaf postlists.
4 /* Copyright (C) 2007,2009,2011,2013,2015,2016,2017 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
33 /** Abstract base class for leaf postlists.
35 * This class provides the following features in addition to the PostList
38 class LeafPostList
: public PostList
{
39 /// Don't allow assignment.
40 void operator=(const LeafPostList
&);
42 /// Don't allow copying.
43 LeafPostList(const LeafPostList
&);
46 const Xapian::Weight
* weight
;
48 /// The term name for this postlist (empty for an alldocs postlist).
51 /// Only constructable as a base class for derived classes.
52 explicit LeafPostList(const std::string
& term_
)
53 : weight(0), term(term_
) { }
58 /** Set the weighting scheme to use during matching.
60 * If this isn't called, get_weight() and recalc_maxweight() will both
63 * You should not call this more than once on a particular object.
65 * @param weight_ The weighting object to use. Must not be NULL.
67 void set_termweight(const Xapian::Weight
* weight_
) {
68 // This method shouldn't be called more than once on the same object.
73 double resolve_lazy_termweight(Xapian::Weight
* weight_
,
74 Xapian::Weight::Internal
* stats
,
75 Xapian::termcount qlen
,
76 Xapian::termcount wqf
,
79 weight_
->init_(*stats
, qlen
, term
, wqf
, factor
);
80 // There should be an existing LazyWeight set already.
82 const Xapian::Weight
* const_weight_
= weight_
;
83 std::swap(weight
, const_weight_
);
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_weight(Xapian::termcount doclen
,
101 Xapian::termcount unique_terms
) const;
103 double recalc_maxweight();
105 TermFreqs
get_termfreq_est_using_stats(
106 const Xapian::Weight::Internal
& stats
) const;
108 Xapian::termcount
count_matching_subqs() const;
110 void gather_position_lists(OrPositionList
* orposlist
);
112 /** Open another postlist from the same database.
114 * @param term_ The term to open a postlist for (must not be an empty
115 * string). If term_ is near to this postlist's term,
116 * then this can be a lot more efficient (and if it isn't
117 * very near, there's not much of a penalty). Using this
118 * method can make a wildcard expansion much more memory
121 * @param need_pos Does the postlist need to support read_position_list()?
122 * Note that open_position_list() may still be called even
123 * if need_pos is false.
125 * @return The new postlist object, or NULL if not supported
126 * (in which case the caller should probably open the
127 * postlist via the database instead).
129 virtual LeafPostList
* open_nearby_postlist(const std::string
& term_
,
130 bool need_pos
) const;
132 /** Set the term name.
134 * This is useful when we optimise a term matching all documents to an
135 * all documents postlist under OP_SYNONYM, as the term name is used by
136 * LeafPostList::get_termfreq_est_using_stats() to locate the appropriate
139 void set_term(const std::string
& term_
) { term
= term_
; }
142 #endif // XAPIAN_INCLUDED_LEAFPOSTLIST_H