matcher/andmaybepostlist.cc

Go to the documentation of this file.
00001 /* andmaybepostlist.cc: Merged postlist; items from one list, weights from both
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2003,2004,2005 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
00021  */
00022 
00023 #include <config.h>
00024 
00025 #include "andmaybepostlist.h"
00026 #include "andpostlist.h"
00027 #include "omassert.h"
00028 #include "omdebug.h"
00029 
00030 PostList *
00031 AndMaybePostList::process_next_or_skip_to(Xapian::weight w_min, PostList *ret)
00032 {
00033     DEBUGCALL(MATCH, PostList *, "AndMaybePostList::process_next_or_skip_to", w_min << ", " << ret);
00034     handle_prune(l, ret);
00035     if (l->at_end()) {
00036         // once l is over, so is the AND MAYBE
00037         lhead = 0;
00038         RETURN(NULL);
00039     }
00040 
00041     lhead = l->get_docid();
00042     if (lhead <= rhead) RETURN(NULL);
00043 
00044     skip_to_handling_prune(r, lhead, w_min - lmax, matcher);
00045     if (r->at_end()) {
00046         PostList *tmp = l;
00047         l = NULL;
00048         RETURN(tmp);
00049     }
00050     rhead = r->get_docid();
00051     RETURN(NULL);
00052 }
00053 
00054 PostList *
00055 AndMaybePostList::next(Xapian::weight w_min)
00056 {
00057     DEBUGCALL(MATCH, PostList *, "AndMaybePostList::next", w_min);
00058     if (w_min > lmax) {
00059         // we can replace the AND MAYBE with an AND
00060         PostList *ret;
00061         DEBUGLINE(MATCH, "AND MAYBE -> AND");
00062         ret = new AndPostList(l, r, matcher, dbsize, true);
00063         l = r = NULL;
00064         skip_to_handling_prune(ret, std::max(lhead, rhead) + 1, w_min, matcher);
00065         RETURN(ret);
00066     }
00067     RETURN(process_next_or_skip_to(w_min, l->next(w_min - rmax)));
00068 }
00069 
00070 PostList *
00071 AndMaybePostList::skip_to(Xapian::docid did, Xapian::weight w_min)
00072 {
00073     DEBUGCALL(MATCH, PostList *, "AndMaybePostList::skip_to", did << ", " << w_min);
00074     if (w_min > lmax) {
00075         // we can replace the AND MAYBE with an AND
00076         PostList *ret;
00077         DEBUGLINE(MATCH, "AND MAYBE -> AND (in skip_to)");
00078         ret = new AndPostList(l, r, matcher, dbsize, true);
00079         did = std::max(did, std::max(lhead, rhead));
00080         l = r = NULL;
00081         skip_to_handling_prune(ret, did, w_min, matcher);
00082         RETURN(ret);
00083     }
00084 
00085     // exit if we're already past the skip point (or at it)
00086     if (did <= lhead) RETURN(NULL);
00087 
00088     RETURN(process_next_or_skip_to(w_min, l->skip_to(did, w_min - rmax)));
00089 }
00090 
00091 Xapian::doccount
00092 AndMaybePostList::get_termfreq_max() const
00093 {
00094     DEBUGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_max", "");
00095     // Termfreq is exactly that of left hand branch.
00096     RETURN(l->get_termfreq_max());
00097 }
00098 
00099 Xapian::doccount
00100 AndMaybePostList::get_termfreq_min() const
00101 {
00102     DEBUGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_min", "");
00103     // Termfreq is exactly that of left hand branch.
00104     RETURN(l->get_termfreq_min());
00105 }
00106 
00107 Xapian::doccount
00108 AndMaybePostList::get_termfreq_est() const
00109 {
00110     DEBUGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_est", "");
00111     // Termfreq is exactly that of left hand branch.
00112     RETURN(l->get_termfreq_est());
00113 }
00114 
00115 Xapian::docid
00116 AndMaybePostList::get_docid() const
00117 {
00118     DEBUGCALL(MATCH, Xapian::docid, "AndMaybePostList::get_docid", "");
00119     Assert(lhead != 0 && rhead != 0); // check we've started
00120     RETURN(lhead);
00121 }
00122 
00123 // only called if we are doing a probabilistic AND MAYBE
00124 Xapian::weight
00125 AndMaybePostList::get_weight() const
00126 {
00127     DEBUGCALL(MATCH, Xapian::weight, "AndMaybePostList::get_weight", "");
00128     Assert(lhead != 0 && rhead != 0); // check we've started
00129     if (lhead == rhead) RETURN(l->get_weight() + r->get_weight());
00130     RETURN(l->get_weight());
00131 }
00132 
00133 // only called if we are doing a probabilistic operation
00134 Xapian::weight
00135 AndMaybePostList::get_maxweight() const
00136 {
00137     DEBUGCALL(MATCH, Xapian::weight, "AndMaybePostList::get_maxweight", "");
00138     RETURN(lmax + rmax);
00139 }
00140 
00141 Xapian::weight
00142 AndMaybePostList::recalc_maxweight()
00143 {
00144     DEBUGCALL(MATCH, Xapian::weight, "AndMaybePostList::recalc_maxweight", "");
00145     lmax = l->recalc_maxweight();
00146     rmax = r->recalc_maxweight();
00147     RETURN(AndMaybePostList::get_maxweight());
00148 }
00149 
00150 bool
00151 AndMaybePostList::at_end() const
00152 {
00153     DEBUGCALL(MATCH, bool, "AndMaybePostList::at_end", "");
00154     RETURN(lhead == 0);
00155 }
00156 
00157 std::string
00158 AndMaybePostList::get_description() const
00159 {
00160     return "(" + l->get_description() + " AndMaybe " + r->get_description() +
00161            ")";
00162 }
00163 
00164 Xapian::doclength
00165 AndMaybePostList::get_doclength() const
00166 {
00167     DEBUGCALL(MATCH, Xapian::doclength, "AndMaybePostList::get_doclength", "");
00168     Assert(lhead != 0 && rhead != 0); // check we've started
00169     if (lhead == rhead) AssertEqDouble(l->get_doclength(), r->get_doclength());
00170     RETURN(l->get_doclength());
00171 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.