1 /** @file honey_positionlist.h
2 * @brief A position list in a honey database.
4 /* Copyright (C) 2005,2006,2008,2009,2010,2011,2013,2016,2017 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
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.
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
22 #ifndef XAPIAN_INCLUDED_HONEY_POSITIONLIST_H
23 #define XAPIAN_INCLUDED_HONEY_POSITIONLIST_H
25 #include <xapian/types.h>
27 #include "backends/positionlist.h"
28 #include "bitstream.h"
29 #include "honey_cursor.h"
30 #include "honey_lazytable.h"
37 class HoneyPositionTable
: public HoneyLazyTable
{
39 static string
make_key(Xapian::docid did
, const string
& term
) {
41 pack_string_preserving_sort(key
, term
);
42 pack_uint_preserving_sort(key
, did
);
46 /** Create a new HoneyPositionTable object.
48 * This method does not create or open the table on disk - you
49 * must call the create() or open() methods respectively!
51 * @param dbdir The directory the honey database is stored in.
52 * @param readonly true if we're opening read-only, else false.
54 HoneyPositionTable(const string
& dbdir
, bool readonly
)
55 : HoneyLazyTable("position", dbdir
+ "/position.", readonly
) { }
57 HoneyPositionTable(int fd
, off_t offset_
, bool readonly_
)
58 : HoneyLazyTable("position", fd
, offset_
, readonly_
) { }
60 /** Pack a position list into a string.
62 * @param s The string to append the position list data to.
64 void pack(string
& s
, const Xapian::VecCOW
<Xapian::termpos
> & vec
) const;
66 /** Set the position list for term tname in document did.
68 void set_positionlist(Xapian::docid did
, const string
& tname
,
70 add(make_key(did
, tname
), s
);
73 /// Delete the position list for term tname in document did.
74 void delete_positionlist(Xapian::docid did
, const string
& tname
) {
75 del(make_key(did
, tname
));
78 /// Return the number of entries in specified position list.
79 Xapian::termcount
positionlist_count(Xapian::docid did
,
80 const string
& term
) const;
83 /** Base-class for a position list in a honey database. */
84 class HoneyBasePositionList
: public PositionList
{
85 /// Copying is not allowed.
86 HoneyBasePositionList(const HoneyBasePositionList
&) = delete;
88 /// Assignment is not allowed.
89 HoneyBasePositionList
& operator=(const HoneyBasePositionList
&) = delete;
92 /// Interpolative decoder.
96 Xapian::termpos current_pos
;
101 /// Number of entries.
102 Xapian::termcount size
;
104 /// Have we started iterating yet?
108 /// Default constructor.
109 HoneyBasePositionList() {}
111 /// Returns size of position list.
112 Xapian::termcount
get_approx_size() const;
114 /** Returns current position.
116 * Either next() or skip_to() must have been called before this
117 * method can be called.
119 Xapian::termpos
get_position() const;
121 /// Advance to the next term position in the list.
124 /// Advance to the first term position which is at least termpos.
125 bool skip_to(Xapian::termpos termpos
);
128 /** A position list in a honey database. */
129 class HoneyPositionList
: public HoneyBasePositionList
{
130 /// The encoded positional data being read by rd.
131 std::string pos_data
;
133 /// Copying is not allowed.
134 HoneyPositionList(const HoneyPositionList
&) = delete;
136 /// Assignment is not allowed.
137 HoneyPositionList
& operator=(const HoneyPositionList
&) = delete;
140 /// Construct and initialise with data.
142 HoneyPositionList(const string
& data
);
144 /// Construct and initialise with data.
145 HoneyPositionList(const HoneyTable
& table
,
150 /** A reusable position list in a honey database. */
151 class HoneyRePositionList
: public HoneyBasePositionList
{
152 /// Cursor for locating multiple entries efficiently.
155 /// Copying is not allowed.
156 HoneyRePositionList(const HoneyRePositionList
&) = delete;
158 /// Assignment is not allowed.
159 HoneyRePositionList
& operator=(const HoneyRePositionList
&) = delete;
164 HoneyRePositionList(const HoneyTable
& table
)
167 /** Fill list with data, and move the position to the start. */
168 void read_data(Xapian::docid did
, const string
& term
);
171 #endif /* XAPIAN_INCLUDED_HONEY_POSITIONLIST_H */