2 * @brief Combine subqueries, weighting as if they are synonyms
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
25 #include "synonympostlist.h"
27 #include "branchpostlist.h"
31 SynonymPostList::~SynonymPostList()
38 SynonymPostList::set_weight(const Xapian::Weight
* 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_();
48 SynonymPostList::next(double w_min
)
50 LOGCALL(MATCH
, PostList
*, "SynonymPostList::next", w_min
);
52 next_handling_prune(subtree
, 0, matcher
);
57 SynonymPostList::skip_to(Xapian::docid did
, double w_min
)
59 LOGCALL(MATCH
, PostList
*, "SynonymPostList::skip_to", did
| w_min
);
61 skip_to_handling_prune(subtree
, did
, 0, matcher
);
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();
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());
95 Xapian::termcount doclen
= want_doclength
? get_doclength() : 0;
96 RETURN(wt
->get_sumpart(0, doclen
, unique_terms
));
100 SynonymPostList::get_maxweight() const
102 LOGCALL(MATCH
, double, "SynonymPostList::get_maxweight", NO_ARGS
);
103 RETURN(wt
->get_maxpart());
107 SynonymPostList::recalc_maxweight()
109 LOGCALL(MATCH
, double, "SynonymPostList::recalc_maxweight", NO_ARGS
);
110 RETURN(SynonymPostList::get_maxweight());
114 SynonymPostList::get_wdf() const {
115 LOGCALL(MATCH
, Xapian::termcount
, "SynonymPostList::get_wdf", NO_ARGS
);
116 RETURN(subtree
->get_wdf());
120 SynonymPostList::get_termfreq_min() const {
121 LOGCALL(MATCH
, Xapian::doccount
, "SynonymPostList::get_termfreq_min", NO_ARGS
);
122 RETURN(subtree
->get_termfreq_min());
126 SynonymPostList::get_termfreq_est() const {
127 LOGCALL(MATCH
, Xapian::doccount
, "SynonymPostList::get_termfreq_est", NO_ARGS
);
128 RETURN(subtree
->get_termfreq_est());
132 SynonymPostList::get_termfreq_max() const {
133 LOGCALL(MATCH
, Xapian::doccount
, "SynonymPostList::get_termfreq_max", NO_ARGS
);
134 RETURN(subtree
->get_termfreq_max());
138 SynonymPostList::get_docid() const {
139 LOGCALL(MATCH
, Xapian::docid
, "SynonymPostList::get_docid", NO_ARGS
);
140 RETURN(subtree
->get_docid());
144 SynonymPostList::get_doclength() const {
145 LOGCALL(MATCH
, Xapian::termcount
, "SynonymPostList::get_doclength", NO_ARGS
);
146 RETURN(subtree
->get_doclength());
150 SynonymPostList::get_unique_terms() const {
151 LOGCALL(MATCH
, Xapian::termcount
, "SynonymPostList::get_unique_terms", NO_ARGS
);
152 RETURN(subtree
->get_unique_terms());
156 SynonymPostList::at_end() const {
157 LOGCALL(MATCH
, bool, "SynonymPostList::at_end", NO_ARGS
);
158 RETURN(subtree
->at_end());
162 SynonymPostList::count_matching_subqs() const
168 SynonymPostList::get_description() const
170 return "(Synonym " + subtree
->get_description() + ")";