backends/flint/flint_modifiedpostlist.cc

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

Documentation for Xapian (version 1.0.20).
Generated on 28 Apr 2010 by Doxygen 1.5.2.