xapian-core  1.4.27
msetpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006,2007,2009,2010,2011,2015 Olly Betts
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <config.h>
22 
23 #include "msetpostlist.h"
24 
25 #include "debuglog.h"
26 #include "omassert.h"
27 
28 #include "xapian/error.h"
29 
30 using namespace std;
31 
34 {
35  LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_min", NO_ARGS);
36  RETURN(mset_internal->matches_lower_bound);
37 }
38 
41 {
42  LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_est", NO_ARGS);
43  RETURN(mset_internal->matches_estimated);
44 }
45 
48 {
49  LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_max", NO_ARGS);
50  RETURN(mset_internal->matches_upper_bound);
51 }
52 
53 double
55 {
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);
60 
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);
67  }
68 
69  // Otherwise max_attained is the best answer we can give.
70  RETURN(mset_internal->max_attained);
71 }
72 
75 {
76  LOGCALL(MATCH, Xapian::docid, "MSetPostList::get_docid", NO_ARGS);
77  Assert(cursor != -1);
78  RETURN(mset_internal->items[cursor].did);
79 }
80 
81 double
83 {
84  LOGCALL(MATCH, double, "MSetPostList::get_weight", NO_ARGS);
85  Assert(cursor != -1);
86  RETURN(mset_internal->items[cursor].wt);
87 }
88 
89 const string *
91 {
92  LOGCALL(MATCH, const string *, "MSetPostList::get_sort_key", NO_ARGS);
93  Assert(cursor != -1);
94  RETURN(&mset_internal->items[cursor].sort_key);
95 }
96 
97 const string *
99 {
100  LOGCALL(MATCH, const string *, "MSetPostList::get_collapse_key", NO_ARGS);
101  Assert(cursor != -1);
102  RETURN(&mset_internal->items[cursor].collapse_key);
103 }
104 
107 {
108  throw Xapian::UnimplementedError("MSetPostList::get_doclength() unimplemented");
109 }
110 
113 {
114  throw Xapian::UnimplementedError("MSetPostList::get_unique_terms() unimplemented");
115 }
116 
117 double
119 {
120  LOGCALL(MATCH, double, "MSetPostList::recalc_maxweight", NO_ARGS);
122 }
123 
124 PostList *
125 MSetPostList::next(double w_min)
126 {
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;
140  }
141  RETURN(NULL);
142 }
143 
144 PostList *
146 {
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");
151 }
152 
153 bool
155 {
156  LOGCALL(MATCH, bool, "MSetPostList::at_end", NO_ARGS);
157  Assert(cursor != -1);
158  RETURN(size_t(cursor) >= mset_internal->items.size());
159 }
160 
161 string
163 {
164  string desc("(MSet ");
165  desc += mset_internal->get_description();
166  desc += ')';
167  return desc;
168 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.
Definition: postlist.h:37
const std::string * get_sort_key() const
Definition: msetpostlist.cc:90
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
Definition: msetpostlist.cc:33
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
STL namespace.
Xapian::docid get_docid() const
Return the current docid.
Definition: msetpostlist.cc:74
bool at_end() const
Return true if the current position is past the last entry in this list.
Hierarchy of classes which Xapian can throw as exceptions.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
std::string get_description() const
Return a string description of this object.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
double get_maxweight() const
Return an upper bound on what get_weight() can return.
Definition: msetpostlist.cc:54
PostList returning entries from an MSet.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
Xapian::termcount get_doclength() const
Not implemented for MSetPostList.
const std::string * get_collapse_key() const
If the collapse key is already known, return it.
Definition: msetpostlist.cc:98
double get_weight() const
Return the weight contribution for the current position.
Definition: msetpostlist.cc:82
Xapian::doccount get_termfreq_est() const
Get an estimate of the number of documents indexed by this term.
Definition: msetpostlist.cc:40
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
Definition: msetpostlist.cc:47
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Various assertion macros.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
PostList * skip_to(Xapian::docid did, double w_min)
Not meaningful for MSetPostList.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487
UnimplementedError indicates an attempt to use an unimplemented feature.
Definition: error.h:325