admin_notes.rst: Actually up to date for 1.4.21
[xapian.git] / xapian-core / matcher / synonympostlist.cc
blobf0bed007f91c7730a6519bb441ef9e77243736f1
1 /** @file
2 * @brief Combine subqueries, weighting as if they are synonyms
3 */
4 /* Copyright 2007,2009 Lemur Consulting Ltd
5 * Copyright 2009,2011,2014,2016,2018 Olly Betts
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
20 * USA
23 #include <config.h>
25 #include "synonympostlist.h"
27 #include "branchpostlist.h"
28 #include "debuglog.h"
29 #include "omassert.h"
31 SynonymPostList::~SynonymPostList()
33 delete wt;
34 delete subtree;
37 void
38 SynonymPostList::set_weight(const Xapian::Weight * wt_)
40 delete wt;
41 wt = wt_;
42 want_doclength = wt->get_sumpart_needs_doclength_();
43 want_wdf = wt->get_sumpart_needs_wdf_();
44 want_unique_terms = wt->get_sumpart_needs_uniqueterms_();
47 PostList *
48 SynonymPostList::next(double w_min)
50 LOGCALL(MATCH, PostList *, "SynonymPostList::next", w_min);
51 (void)w_min;
52 next_handling_prune(subtree, 0, matcher);
53 RETURN(NULL);
56 PostList *
57 SynonymPostList::skip_to(Xapian::docid did, double w_min)
59 LOGCALL(MATCH, PostList *, "SynonymPostList::skip_to", did | w_min);
60 (void)w_min;
61 skip_to_handling_prune(subtree, did, 0, matcher);
62 RETURN(NULL);
65 double
66 SynonymPostList::get_weight() const
68 LOGCALL(MATCH, double, "SynonymPostList::get_weight", NO_ARGS);
69 // The wdf returned can be higher than the doclength. In particular, this
70 // can currently occur if the query contains a term more than once; the wdf
71 // of each occurrence is added up.
73 // However, it's reasonable for weighting algorithms to optimise by
74 // assuming that get_wdf() will never return more than get_doclength(),
75 // since the doclength is the sum of the wdfs.
77 // Therefore, we simply clamp the wdf value to the doclength, to ensure
78 // that this is true. Note that this requires the doclength to be
79 // calculated even if the weight object doesn't want it.
81 Xapian::termcount unique_terms = 0;
82 if (want_unique_terms)
83 unique_terms = get_unique_terms();
84 if (want_wdf) {
85 Xapian::termcount wdf = get_wdf();
86 Xapian::termcount doclen = 0;
87 if (want_doclength || (!wdf_disjoint && wdf > doclen_lower_bound)) {
88 doclen = get_doclength();
89 if (wdf > doclen) wdf = doclen;
91 double sumpart = wt->get_sumpart(wdf, doclen, unique_terms);
92 AssertRel(sumpart, <=, wt->get_maxpart());
93 RETURN(sumpart);
95 Xapian::termcount doclen = want_doclength ? get_doclength() : 0;
96 RETURN(wt->get_sumpart(0, doclen, unique_terms));
99 double
100 SynonymPostList::get_maxweight() const
102 LOGCALL(MATCH, double, "SynonymPostList::get_maxweight", NO_ARGS);
103 RETURN(wt->get_maxpart());
106 double
107 SynonymPostList::recalc_maxweight()
109 LOGCALL(MATCH, double, "SynonymPostList::recalc_maxweight", NO_ARGS);
110 RETURN(SynonymPostList::get_maxweight());
113 Xapian::termcount
114 SynonymPostList::get_wdf() const {
115 LOGCALL(MATCH, Xapian::termcount, "SynonymPostList::get_wdf", NO_ARGS);
116 RETURN(subtree->get_wdf());
119 Xapian::doccount
120 SynonymPostList::get_termfreq_min() const {
121 LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_min", NO_ARGS);
122 RETURN(subtree->get_termfreq_min());
125 Xapian::doccount
126 SynonymPostList::get_termfreq_est() const {
127 LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_est", NO_ARGS);
128 RETURN(subtree->get_termfreq_est());
131 Xapian::doccount
132 SynonymPostList::get_termfreq_max() const {
133 LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_max", NO_ARGS);
134 RETURN(subtree->get_termfreq_max());
137 Xapian::docid
138 SynonymPostList::get_docid() const {
139 LOGCALL(MATCH, Xapian::docid, "SynonymPostList::get_docid", NO_ARGS);
140 RETURN(subtree->get_docid());
143 Xapian::termcount
144 SynonymPostList::get_doclength() const {
145 LOGCALL(MATCH, Xapian::termcount, "SynonymPostList::get_doclength", NO_ARGS);
146 RETURN(subtree->get_doclength());
149 Xapian::termcount
150 SynonymPostList::get_unique_terms() const {
151 LOGCALL(MATCH, Xapian::termcount, "SynonymPostList::get_unique_terms", NO_ARGS);
152 RETURN(subtree->get_unique_terms());
155 bool
156 SynonymPostList::at_end() const {
157 LOGCALL(MATCH, bool, "SynonymPostList::at_end", NO_ARGS);
158 RETURN(subtree->at_end());
161 Xapian::termcount
162 SynonymPostList::count_matching_subqs() const
164 return 1;
167 std::string
168 SynonymPostList::get_description() const
170 return "(Synonym " + subtree->get_description() + ")";