xapian-core  2.0.0
honey_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_HONEY_POSITIONLIST_H
22 #define XAPIAN_INCLUDED_HONEY_POSITIONLIST_H
23 
24 #include <xapian/types.h>
25 
26 #include "backends/positionlist.h"
27 #include "bitstream.h"
28 #include "honey_cursor.h"
29 #include "honey_lazytable.h"
30 #include "pack.h"
31 
32 #include <string>
33 #include <string_view>
34 
39 
42 
43  protected:
46 
49 
52 
55 
58 
64  void set_data(const std::string& data);
65 
66  public:
69 
72 
73  Xapian::termpos back() const;
74 
81 
83  bool next();
84 
87 };
88 
92  std::string pos_data;
93 
96 
99 
100  public:
102  explicit
103  HoneyPositionList(std::string&& data);
104 };
105 
110 
113 
116 
117  public:
119  explicit
121  : cursor(&table) {}
122 
124  void assign_data(std::string&& data);
125 
127  void read_data(Xapian::docid did, const std::string& 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  HoneyPositionTable(const std::string& dbdir, bool readonly)
148  : HoneyLazyTable("position", dbdir + "/position.", readonly) { }
149 
150  HoneyPositionTable(int fd, off_t offset_, bool readonly_)
151  : HoneyLazyTable("position", fd, offset_, readonly_) { }
152 
154  std::string_view term) const {
155  std::string pos_data;
156  if (!get_exact_entry(make_key(did, term), pos_data))
157  return nullptr;
158 
159  return new HoneyPositionList(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 
182  std::string_view term) const;
183 };
184 
185 #endif /* XAPIAN_INCLUDED_HONEY_POSITIONLIST_H */
Classes to encode/decode a bitstream.
Base-class for a position list in a honey database.
Xapian::termcount size
Number of entries.
void set_data(const std::string &data)
Set positional data and start to decode it.
bool skip_to(Xapian::termpos termpos)
Advance to the first term position which is at least termpos.
Xapian::termcount get_approx_size() const
Returns size of position list.
HoneyBasePositionList & operator=(const HoneyBasePositionList &)=delete
Assignment is not allowed.
BitReader rd
Interpolative decoder.
Xapian::termpos current_pos
Current entry.
HoneyBasePositionList()
Default constructor.
Xapian::termpos back() const
Return the final entry in this positionlist.
bool have_started
Have we started iterating yet?
Xapian::termpos get_position() const
Returns current position.
Xapian::termpos last
Last entry.
bool next()
Advance to the next term position in the list.
HoneyBasePositionList(const HoneyBasePositionList &)=delete
Copying is not allowed.
A position list in a honey database.
HoneyPositionList & operator=(const HoneyPositionList &)=delete
Assignment is not allowed.
std::string pos_data
The encoded positional data being read by rd.
HoneyPositionList(const HoneyPositionList &)=delete
Copying is not allowed.
HoneyPositionList * open_position_list(Xapian::docid did, std::string_view term) const
HoneyPositionTable(const std::string &dbdir, bool readonly)
Create a new HoneyPositionTable object.
static std::string make_key(Xapian::docid did, std::string_view term)
Xapian::termcount positionlist_count(Xapian::docid did, std::string_view term) const
Return the number of entries in specified position list.
void delete_positionlist(Xapian::docid did, std::string_view tname)
Delete the position list for term tname in document did.
void pack(std::string &s, const Xapian::VecCOW< Xapian::termpos > &vec) const
Pack a position list into a string.
HoneyPositionTable(int fd, off_t offset_, bool readonly_)
void set_positionlist(Xapian::docid did, std::string_view tname, std::string_view s)
Set the position list for term tname in document did.
A reusable position list in a honey database.
HoneyRePositionList & operator=(const HoneyRePositionList &)=delete
Assignment is not allowed.
HoneyRePositionList(const HoneyRePositionList &)=delete
Copying is not allowed.
HoneyCursor cursor
Cursor for locating multiple entries efficiently.
void read_data(Xapian::docid did, const std::string &term)
Fill list with data, and move the position to the start.
void assign_data(std::string &&data)
Fill list with data, and move the position to the start.
HoneyRePositionList(const HoneyTable &table)
Constructor.
bool get_exact_entry(std::string_view key, std::string *tag) const
Definition: honey_table.cc:247
void add(std::string_view key, const char *val, size_t val_size, bool compressed=false)
Definition: honey_table.cc:74
bool del(const std::string &)
Definition: honey_table.h:671
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
HoneyCursor class.
Subclass of HoneyTable 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