00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "externalpostlist.h"
00025
00026 #include <xapian/postingsource.h>
00027
00028 #include "debuglog.h"
00029 #include "omassert.h"
00030
00031 using namespace std;
00032
00033 ExternalPostList::ExternalPostList(const Xapian::Database & db,
00034 Xapian::PostingSource *source_,
00035 double factor_,
00036 MultiMatch * matcher)
00037 : source(source_), source_is_owned(false), current(0), factor(factor_)
00038 {
00039 Assert(source);
00040 Xapian::PostingSource * newsource = source->clone();
00041 if (newsource != NULL) {
00042 source = newsource;
00043 source_is_owned = true;
00044 }
00045 source->register_matcher_(static_cast<void*>(matcher));
00046 source->init(db);
00047 }
00048
00049 ExternalPostList::~ExternalPostList()
00050 {
00051 if (source_is_owned) {
00052 delete source;
00053 }
00054 }
00055
00056 Xapian::doccount
00057 ExternalPostList::get_termfreq_min() const
00058 {
00059 Assert(source);
00060 return source->get_termfreq_min();
00061 }
00062
00063 Xapian::doccount
00064 ExternalPostList::get_termfreq_est() const
00065 {
00066 Assert(source);
00067 return source->get_termfreq_est();
00068 }
00069
00070 Xapian::doccount
00071 ExternalPostList::get_termfreq_max() const
00072 {
00073 Assert(source);
00074 return source->get_termfreq_max();
00075 }
00076
00077 Xapian::weight
00078 ExternalPostList::get_maxweight() const
00079 {
00080 LOGCALL(MATCH, Xapian::weight, "ExternalPostList::get_maxweight", NO_ARGS);
00081
00082 if (source == NULL) RETURN(0.0);
00083 if (factor == 0.0) RETURN(0.0);
00084 RETURN(factor * source->get_maxweight());
00085 }
00086
00087 Xapian::docid
00088 ExternalPostList::get_docid() const
00089 {
00090 LOGCALL(MATCH, Xapian::docid, "ExternalPostList::get_docid", NO_ARGS);
00091 Assert(current);
00092 RETURN(current);
00093 }
00094
00095 Xapian::weight
00096 ExternalPostList::get_weight() const
00097 {
00098 LOGCALL(MATCH, Xapian::weight, "ExternalPostList::get_weight", NO_ARGS);
00099 Assert(source);
00100 if (factor == 0.0) RETURN(factor);
00101 RETURN(factor * source->get_weight());
00102 }
00103
00104 Xapian::termcount
00105 ExternalPostList::get_doclength() const
00106 {
00107 Assert(false);
00108 return 0;
00109 }
00110
00111 Xapian::weight
00112 ExternalPostList::recalc_maxweight()
00113 {
00114 return ExternalPostList::get_maxweight();
00115 }
00116
00117 PositionList *
00118 ExternalPostList::read_position_list()
00119 {
00120 return NULL;
00121 }
00122
00123 PositionList *
00124 ExternalPostList::open_position_list() const
00125 {
00126 return NULL;
00127 }
00128
00129 PostList *
00130 ExternalPostList::update_after_advance() {
00131 LOGCALL(MATCH, PostList *, "ExternalPostList::update_after_advance", NO_ARGS);
00132 Assert(source);
00133 if (source->at_end()) {
00134 LOGLINE(MATCH, "ExternalPostList now at end");
00135 if (source_is_owned) delete source;
00136 source = NULL;
00137 } else {
00138 current = source->get_docid();
00139 }
00140 RETURN(NULL);
00141 }
00142
00143 PostList *
00144 ExternalPostList::next(Xapian::weight w_min)
00145 {
00146 LOGCALL(MATCH, PostList *, "ExternalPostList::next", w_min);
00147 Assert(source);
00148 source->next(w_min);
00149 RETURN(update_after_advance());
00150 }
00151
00152 PostList *
00153 ExternalPostList::skip_to(Xapian::docid did, Xapian::weight w_min)
00154 {
00155 LOGCALL(MATCH, PostList *, "ExternalPostList::skip_to", did | w_min);
00156 Assert(source);
00157 if (did <= current) RETURN(NULL);
00158 source->skip_to(did, w_min);
00159 RETURN(update_after_advance());
00160 }
00161
00162 PostList *
00163 ExternalPostList::check(Xapian::docid did, Xapian::weight w_min, bool &valid)
00164 {
00165 LOGCALL(MATCH, PostList *, "ExternalPostList::check", did | w_min | valid);
00166 Assert(source);
00167 if (did <= current) {
00168 valid = true;
00169 RETURN(NULL);
00170 }
00171 valid = source->check(did, w_min);
00172 if (source->at_end()) {
00173 LOGLINE(MATCH, "ExternalPostList now at end");
00174 if (source_is_owned) delete source;
00175 source = NULL;
00176 } else {
00177 current = valid ? source->get_docid() : current;
00178 }
00179 RETURN(NULL);
00180 }
00181
00182 bool
00183 ExternalPostList::at_end() const
00184 {
00185 LOGCALL(MATCH, bool, "ExternalPostList::at_end", NO_ARGS);
00186 RETURN(source == NULL);
00187 }
00188
00189 Xapian::termcount
00190 ExternalPostList::count_matching_subqs() const
00191 {
00192 return 1;
00193 }
00194
00195 string
00196 ExternalPostList::get_description() const
00197 {
00198 string desc = "ExternalPostList(";
00199 if (source) desc += source->get_description();
00200 desc += ")";
00201 return desc;
00202 }