Branch data Line data Source code
1 : : /* flint_positionlist.h: A position list in a flint database.
2 : : *
3 : : * Copyright (C) 2005,2006,2008,2010 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 : :
33 : : using namespace std;
34 : :
35 : 2193 : class FlintPositionListTable : public FlintTable {
36 : 776786 : static string make_key(Xapian::docid did, const string & tname) {
37 : 776786 : return F_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 : 2193 : FlintPositionListTable(const string & dbdir, bool readonly)
50 : 2193 : : FlintTable("position", dbdir + "/position.", readonly, DONT_COMPRESS, true) { }
51 : :
52 : : /** Set the position list for term tname in document did.
53 : : *
54 : : * @param check_for_update If true, check if the new list is the same as
55 : : * the existing list (if there is one).
56 : : */
57 : : void set_positionlist(Xapian::docid did, const string & tname,
58 : : Xapian::PositionIterator pos,
59 : : const Xapian::PositionIterator &pos_end,
60 : : bool check_for_update);
61 : :
62 : : /// Delete the position list for term tname in document did.
63 : 22708 : void delete_positionlist(Xapian::docid did, const string & tname) {
64 : 22708 : del(make_key(did, tname));
65 : 22708 : }
66 : :
67 : : /// Return the number of entries in specified position list.
68 : : Xapian::termcount positionlist_count(Xapian::docid did,
69 : : const string & term) const;
70 : : };
71 : :
72 : : /** A position list in a flint database. */
73 [ + - ][ - + ]: 190142 : class FlintPositionList : public PositionList {
74 : : /// Vector of term positions.
75 : : vector<Xapian::termpos> positions;
76 : :
77 : : /// Position of iteration through data.
78 : : vector<Xapian::termpos>::const_iterator current_pos;
79 : :
80 : : /// Have we started iterating yet?
81 : : bool have_started;
82 : :
83 : : /// Advance to next term position.
84 : : void next_internal();
85 : :
86 : : /// Copying is not allowed.
87 : : FlintPositionList(const FlintPositionList &);
88 : :
89 : : /// Assignment is not allowed.
90 : : void operator=(const FlintPositionList &);
91 : :
92 : : public:
93 : : /// Default constructor.
94 : 144909 : FlintPositionList() : have_started(false) {}
95 : :
96 : : /// Construct and initialise with data.
97 : 45233 : FlintPositionList(const FlintTable * table, Xapian::docid did,
98 : 45233 : const string & tname) {
99 : 45233 : (void)read_data(table, did, tname);
100 : 45233 : }
101 : :
102 : : /** Fill list with data, and move the position to the start.
103 : : *
104 : : * @return true if position data was read.
105 : : */
106 : : bool read_data(const FlintTable * table, Xapian::docid did,
107 : : const string & tname);
108 : :
109 : : /// Returns size of position list.
110 : : Xapian::termcount get_size() const;
111 : :
112 : : /** Returns current position.
113 : : *
114 : : * Either next() or skip_to() must have been called before this
115 : : * method can be called.
116 : : */
117 : : Xapian::termpos get_position() const;
118 : :
119 : : /// Advance to the next term position in the list.
120 : : void next();
121 : :
122 : : /// Advance to the first term position which is at least termpos.
123 : : void skip_to(Xapian::termpos termpos);
124 : :
125 : : /// True if we're off the end of the list
126 : : bool at_end() const;
127 : : };
128 : :
129 : : #endif /* XAPIAN_HGUARD_FLINT_POSITIONLIST_H */
|