xapian-core  2.0.0
honey_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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_HONEY_DOCDATA_H
22 #define XAPIAN_INCLUDED_HONEY_DOCDATA_H
23 
24 #include <xapian/types.h>
25 
26 #include "honey_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  HoneyDocDataTable(const std::string& dbdir, bool readonly)
48  : HoneyLazyTable("docdata", dbdir + "/docdata.", readonly) { }
49 
50  HoneyDocDataTable(int fd, off_t offset_, bool readonly)
51  : HoneyLazyTable("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_HONEY_DOCDATA_H
std::string get_document_data(Xapian::docid did) const
Get the document data for document did.
Definition: honey_docdata.h:59
HoneyDocDataTable(const std::string &dbdir, bool readonly)
Create a new HoneyDocDataTable object.
Definition: honey_docdata.h:47
void readahead_for_document(Xapian::docid did) const
void replace_document_data(Xapian::docid did, const std::string &data)
Replace the document data for document did.
Definition: honey_docdata.h:87
static std::string make_key(Xapian::docid did)
Definition: honey_docdata.h:33
HoneyDocDataTable(int fd, off_t offset_, bool readonly)
Definition: honey_docdata.h:50
void add_document_data(Xapian::docid did, const std::string &data)
Set the document data for document did.
Definition: honey_docdata.h:74
bool delete_document_data(Xapian::docid did)
Delete the document data for document did.
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
bool readahead_key(const std::string &) const
Definition: honey_table.h:676
Subclass of HoneyTable for deriving lazy tables from.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Pack types into strings and unpack them again.
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
typedefs for Xapian