1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/** @file flint_modifiedpostlist.cc
* @brief A FlintPostList plus pending modifications
*/
/* Copyright (C) 2006,2007,2009 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "flint_modifiedpostlist.h"
#include "debuglog.h"
#include "flint_database.h"
FlintModifiedPostList::~FlintModifiedPostList()
{
delete poslist;
}
void
FlintModifiedPostList::skip_deletes(Xapian::weight w_min)
{
while (!FlintPostList::at_end()) {
while (it != mods.end() && it->second.first == 'D' &&
it->first < FlintPostList::get_docid())
++it;
if (it == mods.end()) return;
if (it->first != FlintPostList::get_docid()) return;
if (it->second.first != 'D') return;
++it;
FlintPostList::next(w_min);
}
while (it != mods.end() && it->second.first == 'D') ++it;
}
Xapian::doccount
FlintModifiedPostList::get_termfreq() const
{
return this_db->get_termfreq(term);
}
Xapian::docid
FlintModifiedPostList::get_docid() const
{
if (it == mods.end()) return FlintPostList::get_docid();
if (FlintPostList::at_end()) return it->first;
Assert(it->second.first != 'D');
return min(it->first, FlintPostList::get_docid());
}
Xapian::termcount
FlintModifiedPostList::get_doclength() const
{
LOGCALL(DB, Xapian::termcount, "FlintModifiedPostList::get_doclength", NO_ARGS);
if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid()))
RETURN(this_db->get_doclength(it->first));
RETURN(FlintPostList::get_doclength());
}
Xapian::termcount
FlintModifiedPostList::get_wdf() const
{
if (FlintPostList::at_end()) return it->second.second;
Xapian::docid unmod_did = FlintPostList::get_docid();
if (it != mods.end() && it->first <= unmod_did) {
if (it->first < unmod_did) return it->second.second;
return it->second.second;
}
return FlintPostList::get_wdf();
}
PositionList *
FlintModifiedPostList::read_position_list()
{
if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) {
if (poslist) {
delete poslist;
poslist = NULL;
}
poslist = this_db->open_position_list(it->first, term);
return poslist;
}
return FlintPostList::read_position_list();
}
PositionList *
FlintModifiedPostList::open_position_list() const
{
if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) {
return this_db->open_position_list(it->first, term);
}
return FlintPostList::open_position_list();
}
PostList *
FlintModifiedPostList::next(Xapian::weight w_min)
{
if (have_started) {
if (FlintPostList::at_end()) {
++it;
skip_deletes(w_min);
return NULL;
}
Xapian::docid unmod_did = FlintPostList::get_docid();
if (it != mods.end() && it->first <= unmod_did) {
if (it->first < unmod_did && it->second.first != 'D') {
++it;
skip_deletes(w_min);
return NULL;
}
++it;
}
}
FlintPostList::next(w_min);
skip_deletes(w_min);
return NULL;
}
PostList *
FlintModifiedPostList::skip_to(Xapian::docid desired_did, Xapian::weight w_min)
{
if (!FlintPostList::at_end()) FlintPostList::skip_to(desired_did, w_min);
/* FIXME: should we use lower_bound() on the map? */
while (it != mods.end() && it->first < desired_did) ++it;
skip_deletes(w_min);
return NULL;
}
bool
FlintModifiedPostList::at_end() const {
return it == mods.end() && FlintPostList::at_end();
}
std::string
FlintModifiedPostList::get_description() const
{
std::string desc = "FlintModifiedPostList(";
desc += FlintPostList::get_description();
desc += ')';
return desc;
}
|