Branch data Line data Source code
1 : : /** @file synonympostlist.cc
2 : : * @brief Combine subqueries, weighting as if they are synonyms
3 : : */
4 : : /* Copyright 2007,2009 Lemur Consulting Ltd
5 : : * Copyright 2009 Olly Betts
6 : : *
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.
11 : : *
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.
16 : : *
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
21 : : */
22 : :
23 : : #include <config.h>
24 : :
25 : : #include "synonympostlist.h"
26 : :
27 : : #include "branchpostlist.h"
28 : : #include "debuglog.h"
29 : :
30 : 592 : SynonymPostList::~SynonymPostList()
31 : : {
32 [ + - ][ # # ]: 592 : delete wt;
[ # # ]
33 [ + - ][ # # ]: 592 : delete subtree;
[ # # ]
34 [ + - ][ # # ]: 592 : }
[ # # ]
35 : :
36 : : void
37 : 592 : SynonymPostList::set_weight(const Xapian::Weight * wt_)
38 : : {
39 [ - + ]: 592 : delete wt;
40 : 592 : wt = wt_;
41 : 592 : want_doclength = wt->get_sumpart_needs_doclength_();
42 : 592 : want_wdf = wt->get_sumpart_needs_wdf_();
43 : 592 : }
44 : :
45 : : PostList *
46 : 14632 : SynonymPostList::next(Xapian::weight w_min)
47 : : {
48 : : LOGCALL(MATCH, PostList *, "SynonymPostList::next", w_min);
49 : : (void)w_min;
50 : 14632 : next_handling_prune(subtree, 0, matcher);
51 : 14632 : RETURN(NULL);
52 : : }
53 : :
54 : : PostList *
55 : 55 : SynonymPostList::skip_to(Xapian::docid did, Xapian::weight w_min)
56 : : {
57 : : LOGCALL(MATCH, PostList *, "SynonymPostList::skip_to", did | w_min);
58 : : (void)w_min;
59 : 55 : skip_to_handling_prune(subtree, did, 0, matcher);
60 : 55 : RETURN(NULL);
61 : : }
62 : :
63 : : Xapian::weight
64 : 13988 : SynonymPostList::get_weight() const
65 : : {
66 : : LOGCALL(MATCH, Xapian::weight, "SynonymPostList::get_weight", NO_ARGS);
67 : : // The wdf returned can be higher than the doclength. In particular, this
68 : : // can currently occur if the query contains a term more than once; the wdf
69 : : // of each occurrence is added up.
70 : : //
71 : : // However, it's reasonable for weighting algorithms to optimise by
72 : : // assuming that get_wdf() will never return more than get_doclength(),
73 : : // since the doclength is the sum of the wdfs.
74 : : //
75 : : // Therefore, we simply clamp the wdf value to the doclength, to ensure
76 : : // that this is true. Note that this requires the doclength to be
77 : : // calculated even if the weight object doesn't want it.
78 : :
79 [ + - ]: 13988 : if (want_wdf) {
80 : 13988 : Xapian::termcount wdf = get_wdf();
81 : 13988 : Xapian::termcount doclen = get_doclength();
82 [ - + ]: 13988 : if (wdf > doclen) wdf = doclen;
83 : 13988 : RETURN(wt->get_sumpart(wdf, doclen));
84 : : }
85 [ # # ]: 13988 : RETURN(wt->get_sumpart(0, want_doclength ? get_doclength() : 0));
86 : : }
87 : :
88 : : Xapian::weight
89 : 1332 : SynonymPostList::get_maxweight() const
90 : : {
91 : : LOGCALL(MATCH, Xapian::weight, "SynonymPostList::get_maxweight", NO_ARGS);
92 : 1332 : RETURN(wt->get_maxpart());
93 : : }
94 : :
95 : : Xapian::weight
96 : 1022 : SynonymPostList::recalc_maxweight()
97 : : {
98 : : LOGCALL(MATCH, Xapian::weight, "SynonymPostList::recalc_maxweight", NO_ARGS);
99 : :
100 : : // Call recalc_maxweight on the subtree once, to ensure that the maxweights
101 : : // are initialised.
102 [ + + ]: 1022 : if (!have_calculated_subtree_maxweights) {
103 : 592 : subtree->recalc_maxweight();
104 : 592 : have_calculated_subtree_maxweights = true;
105 : : }
106 : 1022 : RETURN(SynonymPostList::get_maxweight());
107 : : }
108 : :
109 : : Xapian::termcount
110 : 13988 : SynonymPostList::get_wdf() const {
111 : : LOGCALL(MATCH, Xapian::termcount, "SynonymPostList::get_wdf", NO_ARGS);
112 : 13988 : RETURN(subtree->get_wdf());
113 : : }
114 : :
115 : : Xapian::doccount
116 : 592 : SynonymPostList::get_termfreq_min() const {
117 : : LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_min", NO_ARGS);
118 : 592 : RETURN(subtree->get_termfreq_min());
119 : : }
120 : :
121 : : Xapian::doccount
122 : 688 : SynonymPostList::get_termfreq_est() const {
123 : : LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_min", NO_ARGS);
124 : 688 : RETURN(subtree->get_termfreq_est());
125 : : }
126 : :
127 : : Xapian::doccount
128 : 592 : SynonymPostList::get_termfreq_max() const {
129 : : LOGCALL(MATCH, Xapian::doccount, "SynonymPostList::get_termfreq_min", NO_ARGS);
130 : 592 : RETURN(subtree->get_termfreq_max());
131 : : }
132 : :
133 : : Xapian::docid
134 : 11397 : SynonymPostList::get_docid() const {
135 : : LOGCALL(MATCH, Xapian::docid, "SynonymPostList::get_docid", NO_ARGS);
136 : 11397 : RETURN(subtree->get_docid());
137 : : }
138 : :
139 : : Xapian::termcount
140 : 13988 : SynonymPostList::get_doclength() const {
141 : : LOGCALL(MATCH, Xapian::termcount, "SynonymPostList::get_doclength", NO_ARGS);
142 : 13988 : RETURN(subtree->get_doclength());
143 : : }
144 : :
145 : : bool
146 : 14768 : SynonymPostList::at_end() const {
147 : : LOGCALL(MATCH, bool, "SynonymPostList::at_end", NO_ARGS);
148 : 14768 : RETURN(subtree->at_end());
149 : : }
150 : :
151 : : Xapian::termcount
152 : 938 : SynonymPostList::count_matching_subqs() const
153 : : {
154 : 938 : return 1;
155 : : }
156 : :
157 : : std::string
158 : 0 : SynonymPostList::get_description() const
159 : : {
160 : 0 : return "(Synonym " + subtree->get_description() + ")";
161 : : }
|