00001 00004 /* Copyright (C) 2006,2007,2009 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (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 USA 00019 */ 00020 00021 #include <config.h> 00022 #include "flint_modifiedpostlist.h" 00023 00024 #include "debuglog.h" 00025 #include "flint_database.h" 00026 00027 FlintModifiedPostList::~FlintModifiedPostList() 00028 { 00029 delete poslist; 00030 } 00031 00032 void 00033 FlintModifiedPostList::skip_deletes(Xapian::weight w_min) 00034 { 00035 while (!FlintPostList::at_end()) { 00036 while (it != mods.end() && it->second.first == 'D' && 00037 it->first < FlintPostList::get_docid()) 00038 ++it; 00039 if (it == mods.end()) return; 00040 if (it->first != FlintPostList::get_docid()) return; 00041 if (it->second.first != 'D') return; 00042 ++it; 00043 FlintPostList::next(w_min); 00044 } 00045 while (it != mods.end() && it->second.first == 'D') ++it; 00046 } 00047 00048 Xapian::doccount 00049 FlintModifiedPostList::get_termfreq() const 00050 { 00051 return this_db->get_termfreq(term); 00052 } 00053 00054 Xapian::docid 00055 FlintModifiedPostList::get_docid() const 00056 { 00057 if (it == mods.end()) return FlintPostList::get_docid(); 00058 if (FlintPostList::at_end()) return it->first; 00059 Assert(it->second.first != 'D'); 00060 return min(it->first, FlintPostList::get_docid()); 00061 } 00062 00063 Xapian::termcount 00064 FlintModifiedPostList::get_doclength() const 00065 { 00066 LOGCALL(DB, Xapian::termcount, "FlintModifiedPostList::get_doclength", NO_ARGS); 00067 if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) 00068 RETURN(this_db->get_doclength(it->first)); 00069 RETURN(FlintPostList::get_doclength()); 00070 } 00071 00072 Xapian::termcount 00073 FlintModifiedPostList::get_wdf() const 00074 { 00075 if (FlintPostList::at_end()) return it->second.second; 00076 Xapian::docid unmod_did = FlintPostList::get_docid(); 00077 if (it != mods.end() && it->first <= unmod_did) { 00078 if (it->first < unmod_did) return it->second.second; 00079 return it->second.second; 00080 } 00081 return FlintPostList::get_wdf(); 00082 } 00083 00084 PositionList * 00085 FlintModifiedPostList::read_position_list() 00086 { 00087 if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) { 00088 if (poslist) { 00089 delete poslist; 00090 poslist = NULL; 00091 } 00092 poslist = this_db->open_position_list(it->first, term); 00093 return poslist; 00094 } 00095 return FlintPostList::read_position_list(); 00096 } 00097 00098 PositionList * 00099 FlintModifiedPostList::open_position_list() const 00100 { 00101 if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) { 00102 return this_db->open_position_list(it->first, term); 00103 } 00104 return FlintPostList::open_position_list(); 00105 } 00106 00107 PostList * 00108 FlintModifiedPostList::next(Xapian::weight w_min) 00109 { 00110 if (have_started) { 00111 if (FlintPostList::at_end()) { 00112 ++it; 00113 skip_deletes(w_min); 00114 return NULL; 00115 } 00116 Xapian::docid unmod_did = FlintPostList::get_docid(); 00117 if (it != mods.end() && it->first <= unmod_did) { 00118 if (it->first < unmod_did && it->second.first != 'D') { 00119 ++it; 00120 skip_deletes(w_min); 00121 return NULL; 00122 } 00123 ++it; 00124 } 00125 } 00126 FlintPostList::next(w_min); 00127 skip_deletes(w_min); 00128 return NULL; 00129 } 00130 00131 PostList * 00132 FlintModifiedPostList::skip_to(Xapian::docid desired_did, Xapian::weight w_min) 00133 { 00134 if (!FlintPostList::at_end()) FlintPostList::skip_to(desired_did, w_min); 00135 /* FIXME: should we use lower_bound() on the map? */ 00136 while (it != mods.end() && it->first < desired_did) ++it; 00137 skip_deletes(w_min); 00138 return NULL; 00139 } 00140 00141 bool 00142 FlintModifiedPostList::at_end() const { 00143 return it == mods.end() && FlintPostList::at_end(); 00144 } 00145 00146 std::string 00147 FlintModifiedPostList::get_description() const 00148 { 00149 std::string desc = "FlintModifiedPostList("; 00150 desc += FlintPostList::get_description(); 00151 desc += ')'; 00152 return desc; 00153 }