xapian-core  1.4.21
glass_docdata.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,2010,2014,2016 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 USA
19  */
20 
21 #ifndef XAPIAN_INCLUDED_GLASS_DOCDATA_H
22 #define XAPIAN_INCLUDED_GLASS_DOCDATA_H
23 
24 #include <xapian/types.h>
25 
26 #include "glass_lazytable.h"
27 #include "pack.h"
28 
29 #include <string>
30 
32  public:
33  static std::string make_key(Xapian::docid did) {
34  std::string key;
35  pack_uint_preserving_sort(key, did);
36  return key;
37  }
38 
47  GlassDocDataTable(const std::string & dbdir, bool readonly)
48  : GlassLazyTable("docdata", dbdir + "/docdata.", readonly) { }
49 
50  GlassDocDataTable(int fd, off_t offset_, bool readonly)
51  : GlassLazyTable("docdata", fd, offset_, readonly) { }
52 
59  std::string get_document_data(Xapian::docid did) const {
60  // We don't store the document data if it is empty.
61  std::string data;
62  (void)get_exact_entry(make_key(did), data);
63  return data;
64  }
65 
74  void add_document_data(Xapian::docid did, const std::string & data) {
75  // We don't store the document data if it is empty.
76  if (!data.empty())
77  add(make_key(did), data);
78  }
79 
87  void replace_document_data(Xapian::docid did, const std::string & data) {
88  if (data.empty()) {
89  // We don't store the document data if it is empty.
91  return;
92  }
93  add(make_key(did), data);
94  }
95 
103  bool delete_document_data(Xapian::docid did) { return del(make_key(did)); }
104 
106  readahead_key(make_key(did));
107  }
108 };
109 
110 #endif // XAPIAN_INCLUDED_GLASS_DOCDATA_H
typedefs for Xapian
bool delete_document_data(Xapian::docid did)
Delete the document data for document did.
bool readahead_key(const string &key) const
Subclass of GlassTable for deriving lazy tables from.
static std::string make_key(Xapian::docid did)
Definition: glass_docdata.h:33
void replace_document_data(Xapian::docid did, const std::string &data)
Replace the document data for document did.
Definition: glass_docdata.h:87
void readahead_for_document(Xapian::docid did) const
void add(const std::string &key, std::string tag, bool already_compressed=false)
Add a key/tag pair to the table, replacing any existing pair with the same key.
std::string get_document_data(Xapian::docid did) const
Get the document data for document did.
Definition: glass_docdata.h:59
GlassDocDataTable(int fd, off_t offset_, bool readonly)
Definition: glass_docdata.h:50
bool get_exact_entry(const std::string &key, std::string &tag) const
Read an entry from the table, if and only if it is exactly that being asked for.
GlassDocDataTable(const std::string &dbdir, bool readonly)
Create a new GlassDocDataTable object.
Definition: glass_docdata.h:47
Pack types into strings and unpack them again.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
void add_document_data(Xapian::docid did, const std::string &data)
Set the document data for document did.
Definition: glass_docdata.h:74
bool del(const std::string &key)
Delete an entry from the table.
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