No longer need to initialise weights under synonym
[xapian.git] / xapian-core / api / leafpostlist.cc
blob16c65c1a5566fcf119f5867a64377854936a0599
1 /** @file leafpostlist.cc
2 * @brief Abstract base class for leaf postlists.
3 */
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
22 #include <config.h>
24 #include "xapian/weight.h"
26 #include "leafpostlist.h"
27 #include "matcher/orpositionlist.h"
28 #include "omassert.h"
29 #include "debuglog.h"
31 using namespace std;
33 LeafPostList::~LeafPostList()
35 delete weight;
38 Xapian::doccount
39 LeafPostList::get_termfreq_min() const
41 return get_termfreq();
44 Xapian::doccount
45 LeafPostList::get_termfreq_max() const
47 return get_termfreq();
50 Xapian::doccount
51 LeafPostList::get_termfreq_est() const
53 return get_termfreq();
56 void
57 LeafPostList::set_termweight(const Xapian::Weight * weight_)
59 // This method shouldn't be called more than once on the same object.
60 Assert(!weight);
61 weight = weight_;
62 need_doclength = weight->get_sumpart_needs_doclength_();
63 need_unique_terms = weight->get_sumpart_needs_uniqueterms_();
66 double
67 LeafPostList::get_maxweight() const
69 return weight ? weight->get_maxpart() : 0;
72 double
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.
79 if (need_doclength)
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());
85 return sumpart;
88 double
89 LeafPostList::recalc_maxweight()
91 return LeafPostList::get_maxweight();
94 TermFreqs
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);
99 if (term.empty()) {
100 RETURN(TermFreqs(stats.collection_size,
101 stats.rset_size,
102 stats.total_term_count));
104 map<string, TermFreqs>::const_iterator i = stats.termfreqs.find(term);
105 Assert(i != stats.termfreqs.end());
106 RETURN(i->second);
109 Xapian::termcount
110 LeafPostList::count_matching_subqs() const
112 return weight ? 1 : 0;
115 void
116 LeafPostList::gather_position_lists(OrPositionList* orposlist)
118 orposlist->add_poslist(read_position_list());
121 LeafPostList *
122 LeafPostList::open_nearby_postlist(const std::string &) const
124 return NULL;