xapian-core  2.0.0
glass_positionlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005-2024 Olly Betts
5  *
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.
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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_GLASS_POSITIONLIST_H
22 #define XAPIAN_INCLUDED_GLASS_POSITIONLIST_H
23 
24 #include <xapian/types.h>
25 
26 #include "bitstream.h"
27 #include "glass_cursor.h"
28 #include "glass_lazytable.h"
29 #include "pack.h"
30 #include "backends/positionlist.h"
31 
32 #include <string>
33 
38 
41 
42  protected:
45 
48 
51 
54 
57 
63  void set_data(std::string_view data);
64 
65  public:
68 
71 
72  Xapian::termpos back() const;
73 
80 
82  bool next();
83 
86 };
87 
91  std::string pos_data;
92 
95 
98 
99  public:
101  explicit
102  GlassPositionList(std::string&& data);
103 };
104 
109 
112 
115 
116  public:
118  explicit
120  : cursor(table) {}
121 
123  void assign_data(std::string&& data);
124 
126  void read_data(Xapian::docid did,
127  std::string_view term);
128 };
129 
131  public:
132  static std::string make_key(Xapian::docid did, std::string_view term) {
133  std::string key;
135  pack_uint_preserving_sort(key, did);
136  return key;
137  }
138 
147  GlassPositionListTable(const std::string& dbdir, bool readonly)
148  : GlassLazyTable("position", dbdir + "/position.", readonly) { }
149 
150  GlassPositionListTable(int fd, off_t offset_, bool readonly_)
151  : GlassLazyTable("position", fd, offset_, readonly_) { }
152 
154  std::string_view term) {
155  std::string pos_data;
156  if (!get_exact_entry(make_key(did, term), pos_data))
157  return nullptr;
158 
159  return new GlassPositionList(std::move(pos_data));
160  }
161 
166  void pack(std::string& s, const Xapian::VecCOW<Xapian::termpos>& vec) const;
167 
170  void set_positionlist(Xapian::docid did, std::string_view tname,
171  std::string_view s) {
172  add(make_key(did, tname), s);
173  }
174 
176  void delete_positionlist(Xapian::docid did, std::string_view tname) {
177  del(make_key(did, tname));
178  }
179 
181  Xapian::termcount positionlist_count(std::string_view data) const;
182 
185  std::string_view term) const;
186 };
187 
188 #endif /* XAPIAN_INCLUDED_GLASS_POSITIONLIST_H */
Classes to encode/decode a bitstream.
Base-class for a position list in a glass database.
GlassBasePositionList()
Default constructor.
bool next()
Advance to the next term position in the list.
BitReader rd
Interpolative decoder.
bool skip_to(Xapian::termpos termpos)
Advance to the first term position which is at least termpos.
bool have_started
Have we started iterating yet?
Xapian::termpos get_position() const
Returns current position.
Xapian::termcount get_approx_size() const
Returns size of position list.
GlassBasePositionList(const GlassBasePositionList &)=delete
Copying is not allowed.
Xapian::termpos current_pos
Current entry.
void set_data(std::string_view data)
Set positional data and start to decode it.
Xapian::termpos last
Last entry.
GlassBasePositionList & operator=(const GlassBasePositionList &)=delete
Assignment is not allowed.
Xapian::termcount size
Number of entries.
Xapian::termpos back() const
Return the final entry in this positionlist.
A cursor pointing to a position in a Btree table, for reading several entries in order,...
Definition: glass_cursor.h:148
void set_positionlist(Xapian::docid did, std::string_view tname, std::string_view s)
Set the position list for term tname in document did.
Xapian::termcount positionlist_count(std::string_view data) const
Return the number of entries in specified position list data.
void pack(std::string &s, const Xapian::VecCOW< Xapian::termpos > &vec) const
Pack a position list into a string.
GlassPositionList * open_position_list(Xapian::docid did, std::string_view term)
GlassPositionListTable(const std::string &dbdir, bool readonly)
Create a new GlassPositionListTable object.
void delete_positionlist(Xapian::docid did, std::string_view tname)
Delete the position list for term tname in document did.
static std::string make_key(Xapian::docid did, std::string_view term)
GlassPositionListTable(int fd, off_t offset_, bool readonly_)
A position list in a glass database.
GlassPositionList(const GlassPositionList &)=delete
Copying is not allowed.
GlassPositionList & operator=(const GlassPositionList &)=delete
Assignment is not allowed.
std::string pos_data
The encoded positional data being read by rd.
A reusable position list in a glass database.
void assign_data(std::string &&data)
Fill list with data, and move the position to the start.
GlassRePositionList(const GlassTable *table)
Constructor.
GlassRePositionList(const GlassRePositionList &)=delete
Copying is not allowed.
void read_data(Xapian::docid did, std::string_view term)
Fill list with data, and move the position to the start.
GlassCursor cursor
Cursor for locating multiple entries efficiently.
GlassRePositionList & operator=(const GlassRePositionList &)=delete
Assignment is not allowed.
Class managing a Btree table in a Glass database.
Definition: glass_table.h:432
bool get_exact_entry(std::string_view key, std::string &tag) const
Read an entry from the table, if and only if it is exactly that being asked for.
bool del(std::string_view key)
Delete an entry from the table.
void add(std::string_view key, std::string_view tag, bool already_compressed=false)
Add a key/tag pair to the table, replacing any existing pair with the same key.
Read a stream created by BitWriter.
Definition: bitstream.h:66
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Suitable for "simple" type T.
Definition: smallvector.h:62
string term
Interface to Btree cursors.
Subclass of GlassTable for deriving lazy tables from.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
Pack types into strings and unpack them again.
void pack_string_preserving_sort(std::string &s, std::string_view value, bool last=false)
Append an encoded std::string to a string, preserving the sort order.
Definition: pack.h:528
void pack_uint_preserving_sort(std::string &s, U value)
Append an encoded unsigned integer to a string, preserving the sort order.
Definition: pack.h:204
Abstract base class for iterating term positions in a document.
typedefs for Xapian