00001 /* multi_termlist.cc: C++ class definition for multiple database access 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2003,2004,2005,2006,2007,2008,2010 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00019 * USA 00020 */ 00021 00022 #include <config.h> 00023 00024 #include "multi_termlist.h" 00025 00026 #include "database.h" 00027 #include "debuglog.h" 00028 #include "expandweight.h" 00029 00030 MultiTermList::MultiTermList(TermList * tl_, 00031 const Xapian::Database &db_, 00032 size_t db_index_) 00033 : tl(tl_), db(db_), db_index(db_index_) 00034 { 00035 termfreq_factor = double(db.get_doccount()); 00036 termfreq_factor /= db.internal[db_index]->get_doccount(); 00037 LOGLINE(DB, "Approximation factor for termfreq: " << termfreq_factor); 00038 } 00039 00040 MultiTermList::~MultiTermList() 00041 { 00042 delete tl; 00043 } 00044 00045 Xapian::termcount 00046 MultiTermList::get_approx_size() const 00047 { 00048 return tl->get_approx_size(); 00049 } 00050 00051 void 00052 MultiTermList::accumulate_stats(Xapian::Internal::ExpandStats & stats) const 00053 { 00054 // For a multidb, every termlist access during expand will be through 00055 // a MultiTermList, so it's safe to just set db_index like this. 00056 stats.db_index = db_index; 00057 tl->accumulate_stats(stats); 00058 } 00059 00060 string 00061 MultiTermList::get_termname() const 00062 { 00063 return tl->get_termname(); 00064 } 00065 00066 Xapian::termcount MultiTermList::get_wdf() const 00067 { 00068 return tl->get_wdf(); 00069 } 00070 00071 Xapian::doccount MultiTermList::get_termfreq() const 00072 { 00073 // Approximate term frequency 00074 return Xapian::doccount(tl->get_termfreq() * termfreq_factor); 00075 } 00076 00077 TermList * MultiTermList::next() 00078 { 00079 return tl->next(); 00080 } 00081 00082 TermList * MultiTermList::skip_to(const string & term) 00083 { 00084 return tl->skip_to(term); 00085 } 00086 00087 bool MultiTermList::at_end() const 00088 { 00089 return tl->at_end(); 00090 } 00091 00092 Xapian::termcount 00093 MultiTermList::positionlist_count() const 00094 { 00095 return tl->positionlist_count(); 00096 } 00097 00098 Xapian::PositionIterator 00099 MultiTermList::positionlist_begin() const 00100 { 00101 return tl->positionlist_begin(); 00102 }