1 /** @file leafpostlist.cc
2 * @brief Abstract base class for leaf postlists.
4 /* Copyright (C) 2007,2009,2011,2013,2014 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
24 #include "xapian/weight.h"
26 #include "leafpostlist.h"
27 #include "matcher/orpositionlist.h"
33 LeafPostList::~LeafPostList()
39 LeafPostList::get_termfreq_min() const
41 return get_termfreq();
45 LeafPostList::get_termfreq_max() const
47 return get_termfreq();
51 LeafPostList::get_termfreq_est() const
53 return get_termfreq();
57 LeafPostList::set_termweight(const Xapian::Weight
* weight_
)
59 // This method shouldn't be called more than once on the same object.
62 need_doclength
= weight
->get_sumpart_needs_doclength_();
63 need_unique_terms
= weight
->get_sumpart_needs_uniqueterms_();
67 LeafPostList::get_maxweight() const
69 return weight
? weight
->get_maxpart() : 0;
73 LeafPostList::get_weight() const
75 if (!weight
) return 0;
76 Xapian::termcount doclen
= 0, unique_terms
= 0;
77 // Fetching the document length and number of unique terms is work we can
78 // avoid if the weighting scheme doesn't use them.
80 doclen
= get_doclength();
81 if (need_unique_terms
)
82 unique_terms
= get_unique_terms();
83 double sumpart
= weight
->get_sumpart(get_wdf(), doclen
, unique_terms
);
84 AssertRel(sumpart
, <=, weight
->get_maxpart());
89 LeafPostList::recalc_maxweight()
91 return LeafPostList::get_maxweight();
95 LeafPostList::get_termfreq_est_using_stats(
96 const Xapian::Weight::Internal
& stats
) const
98 LOGCALL(MATCH
, TermFreqs
, "LeafPostList::get_termfreq_est_using_stats", stats
);
100 RETURN(TermFreqs(stats
.collection_size
,
102 stats
.total_term_count
));
104 map
<string
, TermFreqs
>::const_iterator i
= stats
.termfreqs
.find(term
);
105 Assert(i
!= stats
.termfreqs
.end());
110 LeafPostList::count_matching_subqs() const
112 return weight
? 1 : 0;
116 LeafPostList::gather_position_lists(OrPositionList
* orposlist
)
118 orposlist
->add_poslist(read_position_list());
122 LeafPostList::open_nearby_postlist(const std::string
&) const