File: chert_modifiedpostlist.cc

package info (click to toggle)
xapian-core 1.2.19-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 19,420 kB
  • ctags: 12,656
  • sloc: cpp: 101,561; sh: 11,340; ansic: 8,193; perl: 757; makefile: 635; tcl: 308; python: 40
file content (153 lines) | stat: -rw-r--r-- 4,318 bytes parent folder | download | duplicates (5)
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 chert_modifiedpostlist.cc
 * @brief A ChertPostList plus pending modifications
 */
/* Copyright (C) 2006,2007,2008,2009,2010 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 "chert_modifiedpostlist.h"

#include "chert_database.h"
#include "debuglog.h"

ChertModifiedPostList::~ChertModifiedPostList()
{
    delete poslist;
}

void
ChertModifiedPostList::skip_deletes(Xapian::weight w_min)
{
    while (!ChertPostList::at_end()) {
	while (it != mods.end() && it->second.first == 'D' &&
	       it->first < ChertPostList::get_docid())
	    ++it;
	if (it == mods.end()) return;
	if (it->first != ChertPostList::get_docid()) return;
	if (it->second.first != 'D') return;
	++it;
	ChertPostList::next(w_min);
    }
    while (it != mods.end() && it->second.first == 'D') ++it;
}

Xapian::doccount
ChertModifiedPostList::get_termfreq() const
{
    return this_db->get_termfreq(term);
}

Xapian::docid
ChertModifiedPostList::get_docid() const
{
    if (it == mods.end()) return ChertPostList::get_docid();
    if (ChertPostList::at_end()) return it->first;
    Assert(it->second.first != 'D');
    return min(it->first, ChertPostList::get_docid());
}

Xapian::termcount
ChertModifiedPostList::get_doclength() const
{
    LOGCALL(DB, Xapian::termcount, "ChertModifiedPostList::get_doclength", NO_ARGS);
    if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid()))
	RETURN(this_db->get_doclength(it->first));
    RETURN(ChertPostList::get_doclength());
}

Xapian::termcount
ChertModifiedPostList::get_wdf() const
{
    if (ChertPostList::at_end()) return it->second.second;
    Xapian::docid unmod_did = ChertPostList::get_docid();
    if (it != mods.end() && it->first <= unmod_did) {
	if (it->first < unmod_did) return it->second.second;
	return it->second.second;
    }
    return ChertPostList::get_wdf();
}

PositionList *
ChertModifiedPostList::read_position_list()
{
    if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid())) {
	if (poslist) {
	    delete poslist;
	    poslist = NULL;
	}
	poslist = this_db->open_position_list(it->first, term);
	return poslist;
    }
    return ChertPostList::read_position_list();
}

PositionList *
ChertModifiedPostList::open_position_list() const
{
    if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid())) {
	return this_db->open_position_list(it->first, term);
    }
    return ChertPostList::open_position_list();
}

PostList *
ChertModifiedPostList::next(Xapian::weight w_min)
{
    if (have_started) {
	if (ChertPostList::at_end()) {
	    ++it;
	    skip_deletes(w_min);
	    return NULL;
	}
	Xapian::docid unmod_did = ChertPostList::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;
	}
    }
    ChertPostList::next(w_min);
    skip_deletes(w_min);
    return NULL;
}

PostList *
ChertModifiedPostList::skip_to(Xapian::docid desired_did, Xapian::weight w_min)
{
    if (!ChertPostList::at_end()) ChertPostList::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
ChertModifiedPostList::at_end() const {
    return it == mods.end() && ChertPostList::at_end();
}

std::string
ChertModifiedPostList::get_description() const
{
    std::string desc = "ChertModifiedPostList(";
    desc += ChertPostList::get_description();
    desc += ')';
    return desc;
}