xapian-core  1.4.26
chert_record.cc
Go to the documentation of this file.
1 /* chert_record.cc: Records in chert databases
2  *
3  * Copyright 2002 Ananova Ltd
4  * Copyright 2002,2003,2004,2005,2008 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 #include <config.h>
23 
24 #include "chert_record.h"
25 
26 #include <xapian/error.h>
27 #include "debuglog.h"
28 #include "omassert.h"
29 #include "pack.h"
30 #include "str.h"
31 
32 using std::string;
33 
34 inline string
36 {
37  string key;
39  return key;
40 }
41 
42 string
44 {
45  LOGCALL(DB, string, "ChertRecordTable::get_record", did);
46  string tag;
47  // get_document() checks that the docid is valid, unless DOC_ASSUME_VALID
48  // is used in which case returning an empty string here is the most
49  // sensible behaviour.
50  (void)get_exact_entry(make_key(did), tag);
51  RETURN(tag);
52 }
53 
56 {
57  LOGCALL(DB, Xapian::doccount, "ChertRecordTable::get_doccount", NO_ARGS);
59  if (rare(count > chert_tablesize_t(Xapian::doccount(-1)))) {
60  // If we've got more entries than there are possible docids, the
61  // database is in an odd state.
62  throw Xapian::DatabaseCorruptError("Impossibly many entries in the record table");
63  }
64  RETURN(Xapian::doccount(count));
65 }
66 
67 void
69 {
70  LOGCALL_VOID(DB, "ChertRecordTable::replace_record", data | did);
71  add(make_key(did), data);
72 }
73 
74 void
76 {
77  LOGCALL_VOID(DB, "ChertRecordTable::delete_record", did);
78  if (!del(make_key(did)))
79  throw Xapian::DocNotFoundError("Can't delete non-existent document #" + str(did));
80 }
81 
82 void
84 {
85  readahead_key(make_key(did));
86 }
#define RETURN(A)
Definition: debuglog.h:493
Records in chert databases.
chert_tablesize_t get_entry_count() const
Return a count of the number of entries in the table.
Definition: chert_table.h:623
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:488
Convert types to std::string.
void replace_record(const string &data, Xapian::docid did)
Definition: chert_record.cc:68
#define rare(COND)
Definition: config.h:575
Hierarchy of classes which Xapian can throw as exceptions.
bool readahead_key(const string &key) const
bool del(const std::string &key)
Delete an entry from the table.
void delete_record(Xapian::docid did)
Delete a record from the table.
Definition: chert_record.cc:75
unsigned long long chert_tablesize_t
A type used to store the number of entries in a table.
Definition: chert_types.h:46
void C_pack_uint_preserving_sort(std::string &s, U value)
Append an encoded unsigned integer to a string, preserving the sort order.
Definition: pack.h:149
void readahead_for_record(Xapian::docid did) const
Definition: chert_record.cc:83
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.
string str(int value)
Convert int to std::string.
Definition: str.cc:90
Indicates an attempt to access a document not present in the database.
Definition: error.h:674
DatabaseCorruptError indicates database corruption was detected.
Definition: error.h:409
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.
Definition: chert_table.cc:978
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Pack types into strings and unpack them again.
string get_record(Xapian::docid did) const
Retrieve a document from the table.
Definition: chert_record.cc:43
Various assertion macros.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Xapian::doccount get_doccount() const
Get the number of records in the table.
Definition: chert_record.cc:55
string make_key(Xapian::docid did)
Definition: chert_record.cc:35
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487