matcher/extraweightpostlist.h

Go to the documentation of this file.
00001 /* extraweightpostlist.h: add on extra weight contribution
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2001 Ananova Ltd
00005  * Copyright 2003,2004,2007 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 #ifndef OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
00024 #define OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
00025 
00026 #include "multimatch.h"
00027 
00029 class ExtraWeightPostList : public PostList {
00030     private:
00031         PostList * pl;
00032         Xapian::Weight * wt;
00033         MultiMatch * matcher;
00034         Xapian::weight max_weight;
00035 
00036     public:
00037         Xapian::doccount get_termfreq_max() const {
00038             return pl->get_termfreq_max();
00039         }
00040         Xapian::doccount get_termfreq_min() const {
00041             return pl->get_termfreq_min();
00042         }
00043         Xapian::doccount get_termfreq_est() const {
00044             return pl->get_termfreq_est();
00045         }
00046 
00047         Xapian::docid  get_docid() const { return pl->get_docid(); }
00048 
00049         Xapian::weight get_weight() const {
00050             return pl->get_weight() + wt->get_sumextra(pl->get_doclength());
00051         }
00052 
00053         Xapian::weight get_maxweight() const {
00054             return pl->get_maxweight() + max_weight;
00055         }
00056 
00057         Xapian::weight recalc_maxweight() {
00058             return pl->recalc_maxweight() + max_weight;
00059         }
00060 
00061         PostList *next(Xapian::weight w_min) {
00062             PostList *p = pl->next(w_min - max_weight);
00063             if (p) {
00064                 delete pl;
00065                 pl = p;
00066                 if (matcher) matcher->recalc_maxweight();
00067             }
00068             return NULL;
00069         }
00070 
00071         PostList *skip_to(Xapian::docid did, Xapian::weight w_min) {
00072             PostList *p = pl->skip_to(did, w_min - max_weight);
00073             if (p) {
00074                 delete pl;
00075                 pl = p;
00076                 if (matcher) matcher->recalc_maxweight();
00077             }
00078             return NULL;
00079         }
00080 
00081         bool at_end() const { return pl->at_end(); }
00082 
00083         std::string get_description() const {
00084             return "( ExtraWeight " + pl->get_description() + " )";
00085         }
00086 
00090         virtual Xapian::doclength get_doclength() const {
00091             return pl->get_doclength();
00092         }
00093 
00094         virtual PositionList * read_position_list() {
00095             return pl->read_position_list();
00096         }
00097 
00098         virtual PositionList * open_position_list() const {
00099             return pl->open_position_list();
00100         }
00101 
00102         ExtraWeightPostList(PostList * pl_, Xapian::Weight *wt_,
00103                             MultiMatch *matcher_)
00104             : pl(pl_), wt(wt_), matcher(matcher_),
00105               max_weight(wt->get_maxextra())
00106         { }
00107 
00108         ~ExtraWeightPostList() {
00109             delete pl;
00110             delete wt;
00111         }
00112 };
00113 
00114 #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */

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