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,2009 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 00028 namespace Xapian { 00029 class Weight; 00030 } 00031 00033 class ExtraWeightPostList : public PostList { 00034 private: 00035 PostList * pl; 00036 Xapian::Weight * wt; 00037 MultiMatch * matcher; 00038 Xapian::weight max_weight; 00039 00040 public: 00041 Xapian::doccount get_termfreq_max() const { 00042 return pl->get_termfreq_max(); 00043 } 00044 Xapian::doccount get_termfreq_min() const { 00045 return pl->get_termfreq_min(); 00046 } 00047 Xapian::doccount get_termfreq_est() const { 00048 return pl->get_termfreq_est(); 00049 } 00050 00051 Xapian::docid get_docid() const { return pl->get_docid(); } 00052 00053 Xapian::weight get_weight() const { 00054 return pl->get_weight() + wt->get_sumextra(pl->get_doclength()); 00055 } 00056 00057 Xapian::weight get_maxweight() const { 00058 return pl->get_maxweight() + max_weight; 00059 } 00060 00061 Xapian::weight recalc_maxweight() { 00062 return pl->recalc_maxweight() + max_weight; 00063 } 00064 00065 PostList *next(Xapian::weight w_min) { 00066 PostList *p = pl->next(w_min - max_weight); 00067 if (p) { 00068 delete pl; 00069 pl = p; 00070 if (matcher) matcher->recalc_maxweight(); 00071 } 00072 return NULL; 00073 } 00074 00075 PostList *skip_to(Xapian::docid did, Xapian::weight w_min) { 00076 PostList *p = pl->skip_to(did, w_min - max_weight); 00077 if (p) { 00078 delete pl; 00079 pl = p; 00080 if (matcher) matcher->recalc_maxweight(); 00081 } 00082 return NULL; 00083 } 00084 00085 bool at_end() const { return pl->at_end(); } 00086 00087 std::string get_description() const { 00088 return "( ExtraWeight " + pl->get_description() + " )"; 00089 } 00090 00094 virtual Xapian::termcount get_doclength() const { 00095 return pl->get_doclength(); 00096 } 00097 00098 ExtraWeightPostList(PostList * pl_, Xapian::Weight *wt_, 00099 MultiMatch *matcher_) 00100 : pl(pl_), wt(wt_), matcher(matcher_), 00101 max_weight(wt->get_maxextra()) 00102 { } 00103 00104 ~ExtraWeightPostList() { 00105 delete pl; 00106 delete wt; 00107 } 00108 00109 Xapian::termcount count_matching_subqs() const { 00110 return pl->count_matching_subqs(); 00111 } 00112 }; 00113 00114 #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */