root / tags / 1.0.8 / xapian-core / backends / flint / flint_positionlist.h

Revision 9256, 3.9 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
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* flint_positionlist.h: A position list in a flint database.
2 *
3 * Copyright (C) 2005,2006 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
18 * USA
19 */
20
21#ifndef XAPIAN_HGUARD_FLINT_POSITIONLIST_H
22#define XAPIAN_HGUARD_FLINT_POSITIONLIST_H
23
24#include <xapian/types.h>
25
26#include "flint_table.h"
27#include "flint_utils.h"
28#include "positionlist.h"
29
30#include <string>
31#include <vector>
32
33using namespace std;
34
35class FlintPositionListTable : public FlintTable {
36    static string make_key(Xapian::docid did, const string & tname) {
37        return pack_uint_preserving_sort(did) + tname;
38    }
39
40  public:
41    /** Create a new FlintPositionListTable object.
42     *
43     *  This method does not create or open the table on disk - you
44     *  must call the create() or open() methods respectively!
45     *
46     *  @param dbdir            The directory the flint database is stored in.
47     *  @param readonly         true if we're opening read-only, else false.
48     */
49    FlintPositionListTable(string dbdir, bool readonly)
50        : FlintTable(dbdir + "/position.", readonly, DONT_COMPRESS, true) { }
51
52    /// Set the position list for term tname in document did.
53    void set_positionlist(Xapian::docid did, const string & tname,
54                          Xapian::PositionIterator pos,
55                          const Xapian::PositionIterator &pos_end);
56
57    /// Delete the position list for term tname in document did.
58    void delete_positionlist(Xapian::docid did, const string & tname) {
59        del(make_key(did, tname));
60    }
61
62    /// Return the number of entries in specified position list.
63    Xapian::termcount positionlist_count(Xapian::docid did,
64                                         const string & term) const;
65};
66
67/** A position list in a flint database. */
68class FlintPositionList : public PositionList {
69    /// Vector of term positions.
70    vector<Xapian::termpos> positions;
71
72    /// Position of iteration through data.
73    vector<Xapian::termpos>::const_iterator current_pos;
74
75    /// Have we started iterating yet?
76    bool have_started;
77
78    /// Advance to next term position.
79    void next_internal();
80
81    /// Copying is not allowed.
82    FlintPositionList(const FlintPositionList &);
83
84    /// Assignment is not allowed.
85    void operator=(const FlintPositionList &);
86
87  public:
88    /// Default constructor.
89    FlintPositionList() : have_started(false) {}
90
91    /// Construct and initialise with data.
92    FlintPositionList(const FlintTable * table, Xapian::docid did,
93                      const string & tname) {
94        (void)read_data(table, did, tname);
95    }
96
97    /// Destructor.
98    ~FlintPositionList() { }
99
100    /** Fill list with data, and move the position to the start.
101     *
102     *  @return true if position data was read.
103     */
104    bool read_data(const FlintTable * table, Xapian::docid did,
105                   const string & tname);
106
107    /// Returns size of position list.
108    Xapian::termcount get_size() const;
109
110    /** Returns current position.
111     *
112     *  Either next() or skip_to() must have been called before this
113     *  method can be called.
114     */
115    Xapian::termpos get_position() const;
116
117    /// Advance to the next term position in the list.
118    void next();
119
120    /// Advance to the first term position which is at least termpos.
121    void skip_to(Xapian::termpos termpos);
122
123    /// True if we're off the end of the list
124    bool at_end() const;
125};
126
127#endif /* XAPIAN_HGUARD_FLINT_POSITIONLIST_H */
Note: See TracBrowser for help on using the browser.