xapian-core  1.4.25
glass_positionlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2006,2008,2009,2010,2011,2013,2016,2019 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19  * USA
20  */
21 
22 #ifndef XAPIAN_HGUARD_GLASS_POSITIONLIST_H
23 #define XAPIAN_HGUARD_GLASS_POSITIONLIST_H
24 
25 #include <xapian/types.h>
26 
27 #include "autoptr.h"
28 #include "bitstream.h"
29 #include "glass_lazytable.h"
30 #include "pack.h"
31 #include "backends/positionlist.h"
32 
33 #include <string>
34 
35 using namespace std;
36 
38  public:
39  static string make_key(Xapian::docid did, const string & term) {
40  string key;
41  pack_string_preserving_sort(key, term);
42  pack_uint_preserving_sort(key, did);
43  return key;
44  }
45 
54  GlassPositionListTable(const string & dbdir, bool readonly)
55  : GlassLazyTable("position", dbdir + "/position.", readonly) { }
56 
57  GlassPositionListTable(int fd, off_t offset_, bool readonly_)
58  : GlassLazyTable("position", fd, offset_, readonly_) { }
59 
64  void pack(string & s, const std::vector<Xapian::termpos> & vec) const;
65 
68  void set_positionlist(Xapian::docid did, const string & tname,
69  const string & s) {
70  add(make_key(did, tname), s);
71  }
72 
74  void delete_positionlist(Xapian::docid did, const string & tname) {
75  del(make_key(did, tname));
76  }
77 
79  Xapian::termcount positionlist_count(const string& data) const;
80 
82  Xapian::termcount positionlist_count(Xapian::docid did,
83  const string & term) const;
84 };
85 
90 
93 
96 
99 
101  AutoPtr<GlassCursor> cursor;
102 
105 
108 
110  void operator=(const GlassPositionList &);
111 
112  public:
115 
117  explicit
118  GlassPositionList(const string& data) {
119  read_data(data);
120  }
121 
124  const string & tname) {
125  (void)read_data(table, did, tname);
126  }
127 
132  bool read_data(const string & data);
133 
138  bool read_data(const GlassTable * table, Xapian::docid did,
139  const string & tname);
140 
142  Xapian::termcount get_approx_size() const;
143 
149  Xapian::termpos get_position() const;
150 
152  bool next();
153 
155  bool skip_to(Xapian::termpos termpos);
156 };
157 
158 #endif /* XAPIAN_HGUARD_GLASS_POSITIONLIST_H */
BitReader rd
Interpolative decoder.
typedefs for Xapian
GlassPositionList(const GlassTable *table, Xapian::docid did, const string &tname)
Construct and initialise with data.
Xapian::termpos last
Last entry.
AutoPtr< GlassCursor > cursor
Cursor for locating multiple entries efficiently.
Class managing a Btree table in a Glass database.
Definition: glass_table.h:425
void delete_positionlist(Xapian::docid did, const string &tname)
Delete the position list for term tname in document did.
GlassPositionListTable(int fd, off_t offset_, bool readonly_)
Subclass of GlassTable for deriving lazy tables from.
Abstract base class for iterating term positions in a document.
STL namespace.
GlassPositionList(const string &data)
Construct and initialise with data.
Xapian::termcount size
Number of entries.
A position list in a glass database.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Read a stream created by BitWriter.
Definition: bitstream.h:64
Xapian::termpos current_pos
Current entry.
Classes to encode/decode a bitstream.
GlassPositionListTable(const string &dbdir, bool readonly)
Create a new GlassPositionListTable object.
GlassPositionList()
Default constructor.
bool have_started
Have we started iterating yet?
Pack types into strings and unpack them again.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:83
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
static string make_key(Xapian::docid did, const string &term)
void set_positionlist(Xapian::docid did, const string &tname, const string &s)
Set the position list for term tname in document did.
string make_key(Xapian::docid did)
Definition: chert_record.cc:35
Wrapper around standard unique_ptr template.
void pack_string_preserving_sort(std::string &s, const std::string &value, bool last=false)
Append an encoded std::string to a string, preserving the sort order.
Definition: pack.h:539
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:269