00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "chert_record.h"
00025
00026 #include <xapian/error.h>
00027 #include "debuglog.h"
00028 #include "omassert.h"
00029 #include "pack.h"
00030 #include "str.h"
00031
00032 using std::string;
00033
00034 inline string
00035 make_key(Xapian::docid did)
00036 {
00037 string key;
00038 pack_uint_preserving_sort(key, did);
00039 return key;
00040 }
00041
00042 string
00043 ChertRecordTable::get_record(Xapian::docid did) const
00044 {
00045 LOGCALL(DB, string, "ChertRecordTable::get_record", did);
00046 string tag;
00047
00048 if (!get_exact_entry(make_key(did), tag)) {
00049 throw Xapian::DocNotFoundError("Document " + str(did) + " not found.");
00050 }
00051
00052 RETURN(tag);
00053 }
00054
00055 Xapian::doccount
00056 ChertRecordTable::get_doccount() const
00057 {
00058 LOGCALL(DB, Xapian::doccount, "ChertRecordTable::get_doccount", NO_ARGS);
00059 chert_tablesize_t count = get_entry_count();
00060 if (rare(count > chert_tablesize_t(Xapian::doccount(-1)))) {
00061
00062
00063 throw Xapian::DatabaseCorruptError("Impossibly many entries in the record table");
00064 }
00065 RETURN(Xapian::doccount(count));
00066 }
00067
00068 void
00069 ChertRecordTable::replace_record(const string & data, Xapian::docid did)
00070 {
00071 LOGCALL_VOID(DB, "ChertRecordTable::replace_record", data | did);
00072 add(make_key(did), data);
00073 }
00074
00075 void
00076 ChertRecordTable::delete_record(Xapian::docid did)
00077 {
00078 LOGCALL_VOID(DB, "ChertRecordTable::delete_record", did);
00079 if (!del(make_key(did)))
00080 throw Xapian::DocNotFoundError("Can't delete non-existent document #" + str(did));
00081 }