1 /** @file msetpostlist.cc
2 * @brief PostList returning entries from an MSet
4 /* Copyright (C) 2006,2007,2009,2010,2011,2015 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "msetpostlist.h"
28 #include "xapian/error.h"
33 MSetPostList::get_termfreq_min() const
35 LOGCALL(MATCH
, Xapian::doccount
, "MSetPostList::get_termfreq_min", NO_ARGS
);
36 RETURN(mset_internal
->matches_lower_bound
);
40 MSetPostList::get_termfreq_est() const
42 LOGCALL(MATCH
, Xapian::doccount
, "MSetPostList::get_termfreq_est", NO_ARGS
);
43 RETURN(mset_internal
->matches_estimated
);
47 MSetPostList::get_termfreq_max() const
49 LOGCALL(MATCH
, Xapian::doccount
, "MSetPostList::get_termfreq_max", NO_ARGS
);
50 RETURN(mset_internal
->matches_upper_bound
);
54 MSetPostList::get_maxweight() const
56 LOGCALL(MATCH
, double, "MSetPostList::get_maxweight", NO_ARGS
);
57 // If we've not started, return max_possible from our MSet so that this
58 // value gets used to set max_possible in the combined MSet.
59 if (cursor
== -1) RETURN(mset_internal
->max_possible
);
61 // If the MSet is sorted in descending weight order, then the maxweight we
62 // can return from now on is the weight of the current item.
63 if (decreasing_relevance
) {
64 // FIXME: This is actually a reduction in the maxweight...
65 if (at_end()) RETURN(0);
66 RETURN(mset_internal
->items
[cursor
].wt
);
69 // Otherwise max_attained is the best answer we can give.
70 RETURN(mset_internal
->max_attained
);
74 MSetPostList::get_docid() const
76 LOGCALL(MATCH
, Xapian::docid
, "MSetPostList::get_docid", NO_ARGS
);
78 RETURN(mset_internal
->items
[cursor
].did
);
82 MSetPostList::get_weight() const
84 LOGCALL(MATCH
, double, "MSetPostList::get_weight", NO_ARGS
);
86 RETURN(mset_internal
->items
[cursor
].wt
);
90 MSetPostList::get_sort_key() const
92 LOGCALL(MATCH
, const string
*, "MSetPostList::get_sort_key", NO_ARGS
);
94 RETURN(&mset_internal
->items
[cursor
].sort_key
);
98 MSetPostList::get_collapse_key() const
100 LOGCALL(MATCH
, const string
*, "MSetPostList::get_collapse_key", NO_ARGS
);
101 Assert(cursor
!= -1);
102 RETURN(&mset_internal
->items
[cursor
].collapse_key
);
106 MSetPostList::get_doclength() const
108 throw Xapian::UnimplementedError("MSetPostList::get_doclength() unimplemented");
112 MSetPostList::get_unique_terms() const
114 throw Xapian::UnimplementedError("MSetPostList::get_unique_terms() unimplemented");
118 MSetPostList::recalc_maxweight()
120 LOGCALL(MATCH
, double, "MSetPostList::recalc_maxweight", NO_ARGS
);
121 RETURN(MSetPostList::get_maxweight());
125 MSetPostList::next(double w_min
)
127 LOGCALL(MATCH
, PostList
*, "MSetPostList::next", w_min
);
128 Assert(cursor
== -1 || !at_end());
130 if (decreasing_relevance
) {
131 // MSet items are in decreasing weight order, so if the current item
132 // doesn't have enough weight, none of the remaining items will, so
133 // skip straight to the end.
134 if (!at_end() && mset_internal
->items
[cursor
].wt
< w_min
)
135 cursor
= mset_internal
->items
.size();
137 // Otherwise, skip to the next entry with enough weight.
138 while (!at_end() && mset_internal
->items
[cursor
].wt
< w_min
)
145 MSetPostList::skip_to(Xapian::docid
, double)
147 // The usual semantics of skip_to don't make sense since MSetPostList
148 // returns documents in MSet order rather than docid order like other
150 throw Xapian::InvalidOperationError("MSetPostList::skip_to not meaningful");
154 MSetPostList::at_end() const
156 LOGCALL(MATCH
, bool, "MSetPostList::at_end", NO_ARGS
);
157 Assert(cursor
!= -1);
158 RETURN(size_t(cursor
) >= mset_internal
->items
.size());
162 MSetPostList::get_description() const
164 string
desc("(MSet ");
165 desc
+= mset_internal
->get_description();