scriptindex: Fix weird error cases
[xapian.git] / xapian-core / matcher / msetpostlist.cc
blobbacef17dd22ab83f6bba9c680e61888c2df1f8af
1 /** @file msetpostlist.cc
2 * @brief PostList returning entries from an MSet
3 */
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
21 #include <config.h>
23 #include "msetpostlist.h"
25 #include "debuglog.h"
26 #include "omassert.h"
28 #include "xapian/error.h"
30 using namespace std;
32 Xapian::doccount
33 MSetPostList::get_termfreq_min() const
35 LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_min", NO_ARGS);
36 RETURN(mset_internal->matches_lower_bound);
39 Xapian::doccount
40 MSetPostList::get_termfreq_est() const
42 LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_est", NO_ARGS);
43 RETURN(mset_internal->matches_estimated);
46 Xapian::doccount
47 MSetPostList::get_termfreq_max() const
49 LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_max", NO_ARGS);
50 RETURN(mset_internal->matches_upper_bound);
53 double
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);
73 Xapian::docid
74 MSetPostList::get_docid() const
76 LOGCALL(MATCH, Xapian::docid, "MSetPostList::get_docid", NO_ARGS);
77 Assert(cursor != -1);
78 RETURN(mset_internal->items[cursor].did);
81 double
82 MSetPostList::get_weight() const
84 LOGCALL(MATCH, double, "MSetPostList::get_weight", NO_ARGS);
85 Assert(cursor != -1);
86 RETURN(mset_internal->items[cursor].wt);
89 const string *
90 MSetPostList::get_sort_key() const
92 LOGCALL(MATCH, const string *, "MSetPostList::get_sort_key", NO_ARGS);
93 Assert(cursor != -1);
94 RETURN(&mset_internal->items[cursor].sort_key);
97 const string *
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);
105 Xapian::termcount
106 MSetPostList::get_doclength() const
108 throw Xapian::UnimplementedError("MSetPostList::get_doclength() unimplemented");
111 Xapian::termcount
112 MSetPostList::get_unique_terms() const
114 throw Xapian::UnimplementedError("MSetPostList::get_unique_terms() unimplemented");
117 double
118 MSetPostList::recalc_maxweight()
120 LOGCALL(MATCH, double, "MSetPostList::recalc_maxweight", NO_ARGS);
121 RETURN(MSetPostList::get_maxweight());
124 PostList *
125 MSetPostList::next(double w_min)
127 LOGCALL(MATCH, PostList *, "MSetPostList::next", w_min);
128 Assert(cursor == -1 || !at_end());
129 ++cursor;
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();
136 } else {
137 // Otherwise, skip to the next entry with enough weight.
138 while (!at_end() && mset_internal->items[cursor].wt < w_min)
139 ++cursor;
141 RETURN(NULL);
144 PostList *
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
149 // PostLists do.
150 throw Xapian::InvalidOperationError("MSetPostList::skip_to not meaningful");
153 bool
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());
161 string
162 MSetPostList::get_description() const
164 string desc("(MSet ");
165 desc += mset_internal->get_description();
166 desc += ')';
167 return desc;