00001 00004 /* Copyright (C) 2007,2009 Olly Betts 00005 * Copyright (C) 2009 Lemur Consulting Ltd 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 USA 00020 */ 00021 00022 #include <config.h> 00023 00024 #include "xapian/weight.h" 00025 00026 #include "leafpostlist.h" 00027 #include "omassert.h" 00028 #include "debuglog.h" 00029 00030 using namespace std; 00031 00032 LeafPostList::~LeafPostList() 00033 { 00034 delete weight; 00035 } 00036 00037 Xapian::doccount 00038 LeafPostList::get_termfreq_min() const 00039 { 00040 return get_termfreq(); 00041 } 00042 00043 Xapian::doccount 00044 LeafPostList::get_termfreq_max() const 00045 { 00046 return get_termfreq(); 00047 } 00048 00049 Xapian::doccount 00050 LeafPostList::get_termfreq_est() const 00051 { 00052 return get_termfreq(); 00053 } 00054 00055 void 00056 LeafPostList::set_termweight(const Xapian::Weight * weight_) 00057 { 00058 // This method shouldn't be called more than once on the same object. 00059 Assert(!weight); 00060 weight = weight_; 00061 need_doclength = weight->get_sumpart_needs_doclength_(); 00062 } 00063 00064 Xapian::weight 00065 LeafPostList::get_maxweight() const 00066 { 00067 return weight ? weight->get_maxpart() : 0; 00068 } 00069 00070 Xapian::weight 00071 LeafPostList::get_weight() const 00072 { 00073 if (!weight) return 0; 00074 Xapian::termcount doclen = 0; 00075 // Fetching the document length is work we can avoid if the weighting 00076 // scheme doesn't use it. 00077 if (need_doclength) doclen = get_doclength(); 00078 return weight->get_sumpart(get_wdf(), doclen); 00079 } 00080 00081 Xapian::weight 00082 LeafPostList::recalc_maxweight() 00083 { 00084 return LeafPostList::get_maxweight(); 00085 } 00086 00087 TermFreqs 00088 LeafPostList::get_termfreq_est_using_stats( 00089 const Xapian::Weight::Internal & stats) const 00090 { 00091 LOGCALL(MATCH, TermFreqs, "LeafPostList::get_termfreq_est_using_stats", stats); 00092 if (term.empty()) { 00093 RETURN(TermFreqs(stats.collection_size, stats.rset_size)); 00094 } 00095 map<string, TermFreqs>::const_iterator i = stats.termfreqs.find(term); 00096 Assert(i != stats.termfreqs.end()); 00097 RETURN(i->second); 00098 } 00099 00100 Xapian::termcount 00101 LeafPostList::count_matching_subqs() const 00102 { 00103 return 1; 00104 }