00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <config.h>
00025 #include "andmaybepostlist.h"
00026
00027 #include "debuglog.h"
00028 #include "multiandpostlist.h"
00029 #include "omassert.h"
00030
00031 PostList *
00032 AndMaybePostList::process_next_or_skip_to(Xapian::weight w_min, PostList *ret)
00033 {
00034 LOGCALL(MATCH, PostList *, "AndMaybePostList::process_next_or_skip_to", w_min | ret);
00035 handle_prune(l, ret);
00036 if (l->at_end()) {
00037
00038 lhead = 0;
00039 RETURN(NULL);
00040 }
00041
00042 lhead = l->get_docid();
00043 if (lhead <= rhead) RETURN(NULL);
00044
00045 bool valid;
00046 check_handling_prune(r, lhead, w_min - lmax, matcher, valid);
00047 if (r->at_end()) {
00048 PostList *tmp = l;
00049 l = NULL;
00050 RETURN(tmp);
00051 }
00052 if (valid) {
00053 rhead = r->get_docid();
00054 } else {
00055 rhead = 0;
00056 }
00057 RETURN(NULL);
00058 }
00059
00060 PostList *
00061 AndMaybePostList::sync_rhs(Xapian::weight w_min)
00062 {
00063 LOGCALL(MATCH, PostList *, "AndMaybePostList::sync_rhs", w_min);
00064 bool valid;
00065 check_handling_prune(r, lhead, w_min - lmax, matcher, valid);
00066 if (r->at_end()) {
00067 PostList *tmp = l;
00068 l = NULL;
00069 RETURN(tmp);
00070 }
00071 if (valid) {
00072 rhead = r->get_docid();
00073 } else {
00074 rhead = 0;
00075 }
00076 RETURN(NULL);
00077 }
00078
00079 PostList *
00080 AndMaybePostList::next(Xapian::weight w_min)
00081 {
00082 LOGCALL(MATCH, PostList *, "AndMaybePostList::next", w_min);
00083 if (w_min > lmax) {
00084
00085 PostList *ret;
00086 LOGLINE(MATCH, "AND MAYBE -> AND");
00087 ret = new MultiAndPostList(l, r, lmax, rmax, matcher, dbsize, true);
00088 l = r = NULL;
00089 skip_to_handling_prune(ret, std::max(lhead, rhead) + 1, w_min, matcher);
00090 RETURN(ret);
00091 }
00092 RETURN(process_next_or_skip_to(w_min, l->next(w_min - rmax)));
00093 }
00094
00095 PostList *
00096 AndMaybePostList::skip_to(Xapian::docid did, Xapian::weight w_min)
00097 {
00098 LOGCALL(MATCH, PostList *, "AndMaybePostList::skip_to", did | w_min);
00099 if (w_min > lmax) {
00100
00101 PostList *ret;
00102 LOGLINE(MATCH, "AND MAYBE -> AND (in skip_to)");
00103 ret = new MultiAndPostList(l, r, lmax, rmax, matcher, dbsize, true);
00104 did = std::max(did, std::max(lhead, rhead));
00105 l = r = NULL;
00106 skip_to_handling_prune(ret, did, w_min, matcher);
00107 RETURN(ret);
00108 }
00109
00110
00111 if (did <= lhead) RETURN(NULL);
00112
00113 RETURN(process_next_or_skip_to(w_min, l->skip_to(did, w_min - rmax)));
00114 }
00115
00116 Xapian::doccount
00117 AndMaybePostList::get_termfreq_max() const
00118 {
00119 LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_max", NO_ARGS);
00120
00121 RETURN(l->get_termfreq_max());
00122 }
00123
00124 Xapian::doccount
00125 AndMaybePostList::get_termfreq_min() const
00126 {
00127 LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_min", NO_ARGS);
00128
00129 RETURN(l->get_termfreq_min());
00130 }
00131
00132 Xapian::doccount
00133 AndMaybePostList::get_termfreq_est() const
00134 {
00135 LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_est", NO_ARGS);
00136
00137 RETURN(l->get_termfreq_est());
00138 }
00139
00140 TermFreqs
00141 AndMaybePostList::get_termfreq_est_using_stats(
00142 const Xapian::Weight::Internal & stats) const
00143 {
00144 LOGCALL(MATCH, TermFreqs, "AndMaybePostList::get_termfreq_est_using_stats", stats);
00145
00146 RETURN(l->get_termfreq_est_using_stats(stats));
00147 }
00148
00149 Xapian::docid
00150 AndMaybePostList::get_docid() const
00151 {
00152 LOGCALL(MATCH, Xapian::docid, "AndMaybePostList::get_docid", NO_ARGS);
00153 Assert(lhead != 0);
00154 RETURN(lhead);
00155 }
00156
00157
00158 Xapian::weight
00159 AndMaybePostList::get_weight() const
00160 {
00161 LOGCALL(MATCH, Xapian::weight, "AndMaybePostList::get_weight", NO_ARGS);
00162 Assert(lhead != 0);
00163 if (lhead == rhead) RETURN(l->get_weight() + r->get_weight());
00164 RETURN(l->get_weight());
00165 }
00166
00167
00168 Xapian::weight
00169 AndMaybePostList::get_maxweight() const
00170 {
00171 LOGCALL(MATCH, Xapian::weight, "AndMaybePostList::get_maxweight", NO_ARGS);
00172 RETURN(lmax + rmax);
00173 }
00174
00175 Xapian::weight
00176 AndMaybePostList::recalc_maxweight()
00177 {
00178 LOGCALL(MATCH, Xapian::weight, "AndMaybePostList::recalc_maxweight", NO_ARGS);
00179 lmax = l->recalc_maxweight();
00180 rmax = r->recalc_maxweight();
00181 RETURN(AndMaybePostList::get_maxweight());
00182 }
00183
00184 bool
00185 AndMaybePostList::at_end() const
00186 {
00187 LOGCALL(MATCH, bool, "AndMaybePostList::at_end", NO_ARGS);
00188 RETURN(lhead == 0);
00189 }
00190
00191 std::string
00192 AndMaybePostList::get_description() const
00193 {
00194 return "(" + l->get_description() + " AndMaybe " + r->get_description() +
00195 ")";
00196 }
00197
00198 Xapian::termcount
00199 AndMaybePostList::get_doclength() const
00200 {
00201 LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::get_doclength", NO_ARGS);
00202 Assert(lhead != 0);
00203 if (lhead == rhead) AssertEq(l->get_doclength(), r->get_doclength());
00204 RETURN(l->get_doclength());
00205 }
00206
00207 Xapian::termcount
00208 AndMaybePostList::get_wdf() const
00209 {
00210 LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::get_wdf", NO_ARGS);
00211 if (lhead == rhead) RETURN(l->get_wdf() + r->get_wdf());
00212 RETURN(l->get_wdf());
00213 }
00214
00215 Xapian::termcount
00216 AndMaybePostList::count_matching_subqs() const
00217 {
00218 LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::count_matching_subqs", NO_ARGS);
00219 if (lhead == rhead)
00220 RETURN(l->count_matching_subqs() + r->count_matching_subqs());
00221 RETURN(l->count_matching_subqs());
00222 }