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

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.