xapian-core  1.4.27
multi_postlist.cc
Go to the documentation of this file.
1 
23 #include <config.h>
24 
25 #include "multi_postlist.h"
26 
27 #include "debuglog.h"
28 #include "omassert.h"
29 
30 #ifdef XAPIAN_ASSERTIONS_PARANOID
31 #include "xapian/database.h"
32 #endif
33 
34 MultiPostList::MultiPostList(std::vector<LeafPostList *> & pls,
35  const Xapian::Database &this_db_)
36  : postlists(pls),
37  this_db(this_db_),
38  finished(false),
39  currdoc(0)
40 {
41  multiplier = pls.size();
42 }
43 
44 
46 {
47  std::vector<LeafPostList *>::iterator i;
48  for (i = postlists.begin(); i != postlists.end(); ++i) {
49  delete *i;
50  }
51  postlists.clear();
52 }
53 
56 {
57  // Should never get called.
58  Assert(false);
59  return 0;
60 }
61 
64 {
66 }
67 
70 {
72 }
73 
74 double
76 {
78 }
79 
80 double
82 {
83  // Should never get called.
84  Assert(false);
85  return 0;
86 }
87 
88 double
90 {
92 }
93 
96 {
97  LOGCALL(DB, Xapian::docid, "MultiPostList::get_docid", NO_ARGS);
98  Assert(!at_end());
99  Assert(currdoc != 0);
100  RETURN(currdoc);
101 }
102 
105 {
106  LOGCALL(DB, Xapian::termcount, "MultiPostList::get_doclength", NO_ARGS);
107  Assert(!at_end());
108  Assert(currdoc != 0);
111  RETURN(result);
112 }
113 
116 {
117  LOGCALL(DB, Xapian::termcount, "MultiPostList::get_unique_terms", NO_ARGS);
118  Assert(!at_end());
119  Assert(currdoc != 0);
122  RETURN(result);
123 }
124 
127 {
128  return postlists[(currdoc - 1) % multiplier]->get_wdf();
129 }
130 
131 PositionList *
133 {
134  return postlists[(currdoc - 1) % multiplier]->open_position_list();
135 }
136 
137 PostList *
138 MultiPostList::next(double w_min)
139 {
140  LOGCALL(DB, PostList *, "MultiPostList::next", w_min);
141  Assert(!at_end());
142 
143  Xapian::docid newdoc = 0;
144  Xapian::docid offset = 1;
145  std::vector<LeafPostList *>::iterator i;
146  for (i = postlists.begin(); i != postlists.end(); ++i) {
147  if (!(*i)->at_end()) {
148  Xapian::docid id = ((*i)->get_docid() - 1) * multiplier + offset;
149  // Check if it needs to be advanced
150  if (currdoc >= id) {
151  (*i)->next(w_min);
152  if (!(*i)->at_end()) {
153  id = ((*i)->get_docid() - 1) * multiplier + offset;
154  if (newdoc == 0 || id < newdoc) newdoc = id;
155  }
156  } else {
157  if (newdoc == 0 || id < newdoc) newdoc = id;
158  }
159  }
160  offset++;
161  }
162  if (newdoc) {
163  LOGLINE(DB, "MultiPostList::next() newdoc=" << newdoc <<
164  " (olddoc=" << currdoc << ")");
165  currdoc = newdoc;
166  } else {
167  LOGLINE(DB, "MultiPostList::next() finished" <<
168  " (olddoc=" << currdoc << ")");
169  finished = true;
170  }
171  RETURN(NULL);
172 }
173 
174 PostList *
176 {
177  LOGCALL(DB, PostList *, "MultiPostList::skip_to", did | w_min);
178  Assert(!at_end());
179  Xapian::docid newdoc = 0;
180  Xapian::docid offset = 0;
181  Xapian::docid realdid = (did - 1) / multiplier + 2;
182  Xapian::doccount dbnumber = (did - 1) % multiplier;
183  std::vector<LeafPostList *>::iterator i;
184  for (i = postlists.begin(); i != postlists.end(); ++i) {
185  if (offset == dbnumber) --realdid;
186  ++offset;
187  Assert((realdid - 1) * multiplier + offset >= did);
188  Assert((realdid - 1) * multiplier + offset < did + multiplier);
189  if (!(*i)->at_end()) {
190  (*i)->skip_to(realdid, w_min);
191  if (!(*i)->at_end()) {
192  Xapian::docid id = ((*i)->get_docid() - 1) * multiplier + offset;
193  if (newdoc == 0 || id < newdoc) newdoc = id;
194  }
195  }
196  }
197  if (newdoc) {
198  currdoc = newdoc;
199  } else {
200  finished = true;
201  }
202  RETURN(NULL);
203 }
204 
205 bool
207 {
208  return finished;
209 }
210 
211 std::string
213 {
214  std::string desc;
215 
216  std::vector<LeafPostList *>::const_iterator i;
217  for (i = postlists.begin(); i != postlists.end(); ++i) {
218  if (!desc.empty()) desc += ',';
219  desc += (*i)->get_description();
220  }
221 
222  return desc;
223 }
Xapian::docid currdoc
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
Xapian::doccount multiplier
Abstract base class for postlists.
Definition: postlist.h:37
Xapian::termcount get_doclength() const
Return the length of current document.
std::string get_description() const
Return a string description of this object.
This class is used to access a database, or a group of databases.
Definition: database.h:68
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
MultiPostList(std::vector< LeafPostList *> &pls, const Xapian::Database &this_db_)
Xapian::Database this_db
double get_weight() const
Return the weight contribution for the current position.
std::vector< LeafPostList * > postlists
#define false
Definition: header.h:9
Xapian::docid get_docid() const
Return the current docid.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
bool at_end() const
Return true if the current position is past the last entry in this list.
double get_maxweight() const
Return an upper bound on what get_weight() can return.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
API for working with Xapian databases.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a document.
Definition: omdatabase.cc:461
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
#define AssertEqParanoid(A, B)
Definition: omassert.h:131
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Class for merging PostList objects from subdatabases.
Various assertion macros.
#define LOGLINE(a, b)
Definition: debuglog.h:494
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
Definition: omdatabase.cc:476
Xapian::doccount get_termfreq_est() const
Get an estimate of the number of documents indexed by this term.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487