root / tags / 1.0.8 / xapian-core / backends / flint / flint_modifiedpostlist.cc

Revision 9256, 4.1 kB (checked in by olly, 16 months ago)

common/msvc_posix_wrapper.cc,common/msvc_posix_wrapper.h: Add
msvc_posix_rename() which can rename a file on top of another file.
common/stringutils.h: Add common_prefix_length() function.
backends/flint/: Clean up FlintWritableDatabase? - it now just
inherits from FlintDatabase? which allows several virtual methods
which just forwarded to FlintDatabase? to be dropped. Also, we
now no longer need to pass FlintTable objects to other classes
- they can just find the tables they want via the database pointer.
The never-used "store_termfreqs" flag has been dropped from the
termlist table entries - existing 1.0.x flint databases will be
automatically upgraded to the new version. Opening a database
now calls stat() less, so should be slightly more efficient.
And TermIterator::positionlist_count() now works for the flint
backend.
tests/Makefile.am,tests/api_db.cc,tests/testdata/flint-1.0.2/: New
test flintbackwardcompat2 which tests that we can open a flint
database from 1.0.2.
tests/api_wrdb.cc: New test adddoc4 which checks that termlists
handle an initial term of any valid length correctly.
tests/testdata/flint-1.0.1/postlist.DB: Mark as a binary file in
SVN.

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