xapian-core  1.4.25
externalpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 2008,2009,2010,2011 Olly Betts
5  * Copyright 2009 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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 USA
20  */
21 
22 #include <config.h>
23 
24 #include "externalpostlist.h"
25 
26 #include <xapian/error.h>
27 #include <xapian/postingsource.h>
28 
29 #include "debuglog.h"
30 #include "omassert.h"
31 
32 using namespace std;
33 
35  Xapian::PostingSource* source_,
36  double factor_,
37  MultiMatch* matcher,
38  Xapian::doccount shard_index)
39  : current(0), factor(factor_)
40 {
41  Assert(source_);
42  Xapian::PostingSource* newsource = source_->clone();
43  if (newsource != NULL) {
44  source = newsource->release();
45  } else if (shard_index == 0) {
46  // Allow use of a non-clone-able PostingSource with a non-sharded
47  // Database.
48  source = source_;
49  } else {
50  throw Xapian::InvalidOperationError("PostingSource subclass must "
51  "implement clone() to support use "
52  "with a sharded database");
53  }
54  source->register_matcher_(static_cast<void*>(matcher));
55  source->init(db);
56 }
57 
60 {
61  Assert(source.get());
62  return source->get_termfreq_min();
63 }
64 
67 {
68  Assert(source.get());
69  return source->get_termfreq_est();
70 }
71 
74 {
75  Assert(source.get());
76  return source->get_termfreq_max();
77 }
78 
79 double
81 {
82  LOGCALL(MATCH, double, "ExternalPostList::get_maxweight", NO_ARGS);
83  // source will be NULL here if we've reached the end.
84  if (source.get() == NULL) RETURN(0.0);
85  if (factor == 0.0) RETURN(0.0);
87 }
88 
91 {
92  LOGCALL(MATCH, Xapian::docid, "ExternalPostList::get_docid", NO_ARGS);
93  Assert(current);
94  RETURN(current);
95 }
96 
97 double
99 {
100  LOGCALL(MATCH, double, "ExternalPostList::get_weight", NO_ARGS);
101  Assert(source.get());
102  if (factor == 0.0) RETURN(factor);
104 }
105 
108 {
109  Assert(false);
110  return 0;
111 }
112 
115 {
116  Assert(false);
117  return 0;
118 }
119 
120 double
122 {
124 }
125 
126 PositionList *
128 {
129  return NULL;
130 }
131 
132 PostList *
134  LOGCALL(MATCH, PostList *, "ExternalPostList::update_after_advance", NO_ARGS);
135  Assert(source.get());
136  if (source->at_end()) {
137  LOGLINE(MATCH, "ExternalPostList now at end");
138  source = NULL;
139  } else {
140  current = source->get_docid();
141  }
142  RETURN(NULL);
143 }
144 
145 PostList *
147 {
148  LOGCALL(MATCH, PostList *, "ExternalPostList::next", w_min);
149  Assert(source.get());
150  source->next(w_min);
152 }
153 
154 PostList *
156 {
157  LOGCALL(MATCH, PostList *, "ExternalPostList::skip_to", did | w_min);
158  Assert(source.get());
159  if (did <= current) RETURN(NULL);
160  source->skip_to(did, w_min);
162 }
163 
164 PostList *
165 ExternalPostList::check(Xapian::docid did, double w_min, bool &valid)
166 {
167  LOGCALL(MATCH, PostList *, "ExternalPostList::check", did | w_min | valid);
168  Assert(source.get());
169  if (did <= current) {
170  valid = true;
171  RETURN(NULL);
172  }
173  valid = source->check(did, w_min);
174  if (source->at_end()) {
175  LOGLINE(MATCH, "ExternalPostList now at end");
176  source = NULL;
177  } else {
178  current = valid ? source->get_docid() : current;
179  }
180  RETURN(NULL);
181 }
182 
183 bool
185 {
186  LOGCALL(MATCH, bool, "ExternalPostList::at_end", NO_ARGS);
187  RETURN(source.get() == NULL);
188 }
189 
192 {
193  return 1;
194 }
195 
196 string
198 {
199  string desc = "ExternalPostList(";
200  if (source.get()) desc += source->get_description();
201  desc += ")";
202  return desc;
203 }
virtual void init(const Database &db)=0
Set this PostingSource to the start of the list of postings.
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
bool at_end() const
Return true if the current position is past the last entry in this list.
Abstract base class for postlists.
Definition: postlist.h:37
This class is used to access a database, or a group of databases.
Definition: database.h:68
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
External sources of posting information.
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.
STL namespace.
virtual Xapian::doccount get_termfreq_est() const =0
An estimate of the number of documents this object can return.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
PostList * check(Xapian::docid did, double w_min, bool &valid)
Check if the specified docid occurs in this postlist.
Hierarchy of classes which Xapian can throw as exceptions.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
virtual bool check(Xapian::docid did, double min_wt)
Check if the specified docid occurs.
double get_weight() const
Return the weight contribution for the current position.
virtual Xapian::doccount get_termfreq_max() const =0
An upper bound on the number of documents this object can return.
Xapian::docid get_docid() const
Return the current docid.
void register_matcher_(void *matcher)
Definition: postingsource.h:76
Xapian::doccount get_termfreq_est() const
Get an estimate of the number of documents indexed by this term.
virtual PostingSource * clone() const
Clone the posting source.
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
std::string get_description() const
Return a string description of this object.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
PostList * update_after_advance()
ExternalPostList(const ExternalPostList &)
Disallow copying.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
PostList * skip_to(Xapian::docid, double w_min)
Skip forward to the specified docid.
virtual double get_weight() const
Return the weight contribution for the current document.
Base class which provides an "external" source of postings.
Definition: postingsource.h:47
Xapian::docid current
virtual Xapian::doccount get_termfreq_min() const =0
A lower bound on the number of documents this object can return.
Xapian::Internal::opt_intrusive_ptr< Xapian::PostingSource > source
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
virtual void skip_to(Xapian::docid did, double min_wt)
Advance to the specified docid.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Return document ids from an external source.
PostingSource * release()
Start reference counting this object.
double get_maxweight() const
Return the currently set upper bound on what get_weight() can return.
virtual Xapian::docid get_docid() const =0
Return the current docid.
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
virtual void next(double min_wt)=0
Advance the current position to the next matching document.
Xapian::termcount get_doclength() const
Return the length of current document.
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
virtual std::string get_description() const
Return a string describing this object.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487