Branch data Line data Source code
1 : : /* brass_positionlist.h: A position list in a brass database.
2 : : *
3 : : * Copyright (C) 2005,2006,2008,2009,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_BRASS_POSITIONLIST_H
22 : : #define XAPIAN_HGUARD_BRASS_POSITIONLIST_H
23 : :
24 : : #include <xapian/types.h>
25 : :
26 : : #include "brass_lazytable.h"
27 : : #include "pack.h"
28 : : #include "positionlist.h"
29 : :
30 : : #include <string>
31 : : #include <vector>
32 : :
33 : : using namespace std;
34 : :
35 : 2208 : class BrassPositionListTable : public BrassLazyTable {
36 : : public:
37 : 836052 : static string make_key(Xapian::docid did, const string & term) {
38 : 836052 : string key;
39 : 836052 : pack_uint_preserving_sort(key, did);
40 : 836052 : key += term;
41 : 0 : return key;
42 : : }
43 : :
44 : : /** Create a new BrassPositionListTable object.
45 : : *
46 : : * This method does not create or open the table on disk - you
47 : : * must call the create() or open() methods respectively!
48 : : *
49 : : * @param dbdir The directory the brass database is stored in.
50 : : * @param readonly true if we're opening read-only, else false.
51 : : */
52 : 2208 : BrassPositionListTable(const string & dbdir, bool readonly)
53 : : : BrassLazyTable("position", dbdir + "/position.", readonly,
54 : 2208 : DONT_COMPRESS) { }
55 : :
56 : : /** Set the position list for term tname in document did.
57 : : *
58 : : * @param check_for_update If true, check if the new list is the same as
59 : : * the existing list (if there is one).
60 : : */
61 : : void set_positionlist(Xapian::docid did, const string & tname,
62 : : Xapian::PositionIterator pos,
63 : : const Xapian::PositionIterator &pos_end,
64 : : bool check_for_update);
65 : :
66 : : /// Delete the position list for term tname in document did.
67 : 22708 : void delete_positionlist(Xapian::docid did, const string & tname) {
68 : 22708 : del(make_key(did, tname));
69 : 22708 : }
70 : :
71 : : /// Return the number of entries in specified position list.
72 : : Xapian::termcount positionlist_count(Xapian::docid did,
73 : : const string & term) const;
74 : : };
75 : :
76 : : /** A position list in a brass database. */
77 [ + - ][ - + ]: 190860 : class BrassPositionList : public PositionList {
78 : : /// Vector of term positions.
79 : : vector<Xapian::termpos> positions;
80 : :
81 : : /// Position of iteration through data.
82 : : vector<Xapian::termpos>::const_iterator current_pos;
83 : :
84 : : /// Have we started iterating yet?
85 : : bool have_started;
86 : :
87 : : /// Advance to next term position.
88 : : void next_internal();
89 : :
90 : : /// Copying is not allowed.
91 : : BrassPositionList(const BrassPositionList &);
92 : :
93 : : /// Assignment is not allowed.
94 : : void operator=(const BrassPositionList &);
95 : :
96 : : public:
97 : : /// Default constructor.
98 : 145801 : BrassPositionList() : have_started(false) {}
99 : :
100 : : /// Construct and initialise with data.
101 : 45059 : BrassPositionList(const BrassTable * table, Xapian::docid did,
102 : 45059 : const string & tname) {
103 : 45059 : (void)read_data(table, did, tname);
104 : 45059 : }
105 : :
106 : : /** Fill list with data, and move the position to the start.
107 : : *
108 : : * @return true if position data was read.
109 : : */
110 : : bool read_data(const BrassTable * table, Xapian::docid did,
111 : : const string & tname);
112 : :
113 : : /// Returns size of position list.
114 : : Xapian::termcount get_size() const;
115 : :
116 : : /** Returns current position.
117 : : *
118 : : * Either next() or skip_to() must have been called before this
119 : : * method can be called.
120 : : */
121 : : Xapian::termpos get_position() const;
122 : :
123 : : /// Advance to the next term position in the list.
124 : : void next();
125 : :
126 : : /// Advance to the first term position which is at least termpos.
127 : : void skip_to(Xapian::termpos termpos);
128 : :
129 : : /// True if we're off the end of the list
130 : : bool at_end() const;
131 : : };
132 : :
133 : : #endif /* XAPIAN_HGUARD_BRASS_POSITIONLIST_H */
|