00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <config.h>
00026 #include "quartz_record.h"
00027 #include "quartz_utils.h"
00028 #include "utils.h"
00029 #include <xapian/error.h>
00030 #include "omassert.h"
00031 #include "omdebug.h"
00032
00033 using std::string;
00034
00035
00036
00037 static const string METAINFO_KEY("", 1);
00038
00039 string
00040 QuartzRecordTable::get_record(Xapian::docid did) const
00041 {
00042 DEBUGCALL(DB, string, "QuartzRecordTable::get_record", did);
00043 string key(quartz_docid_to_key(did));
00044 string tag;
00045
00046 if (!get_exact_entry(key, tag)) {
00047 throw Xapian::DocNotFoundError("Document " + om_tostring(did) + " not found.");
00048 }
00049
00050 RETURN(tag);
00051 }
00052
00053
00054 Xapian::doccount
00055 QuartzRecordTable::get_doccount() const
00056 {
00057 DEBUGCALL(DB, Xapian::doccount, "QuartzRecordTable::get_doccount", "");
00058
00059
00060
00061 CASSERT(sizeof(Xapian::doccount) >= sizeof(quartz_tablesize_t));
00062 CASSERT_TYPE_UNSIGNED(Xapian::doccount);
00063 CASSERT_TYPE_UNSIGNED(quartz_tablesize_t);
00064 Xapian::doccount entries = get_entry_count();
00065 RETURN(entries ? entries - 1 : 0);
00066 }
00067
00068 Xapian::docid
00069 QuartzRecordTable::get_lastdocid() const
00070 {
00071 DEBUGCALL(DB, Xapian::docid, "QuartzRecordTable::get_lastdocid", "");
00072
00073 string tag;
00074 if (!get_exact_entry(METAINFO_KEY, tag)) RETURN(0u);
00075
00076 Xapian::docid did;
00077 const char * data = tag.data();
00078 const char * end = data + tag.size();
00079 if (!unpack_uint(&data, end, &did)) {
00080 throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
00081 }
00082 RETURN(did);
00083 }
00084
00085 void
00086 QuartzRecordTable::replace_record(const string & data, Xapian::docid did)
00087 {
00088 DEBUGCALL(DB, void, "QuartzRecordTable::replace_record", data << ", " << did);
00089 string key(quartz_docid_to_key(did));
00090 add(key, data);
00091 }
00092
00093 void
00094 QuartzRecordTable::set_total_length_and_lastdocid(quartz_totlen_t totlen,
00095 Xapian::docid did)
00096 {
00097 DEBUGCALL(DB, void, "QuartzRecordTable::set_total_length_and_lastdocid",
00098 totlen << ", " << did);
00099 string tag = pack_uint(did);
00100 tag += pack_uint_last(totlen);
00101 add(METAINFO_KEY, tag);
00102 }
00103
00104 quartz_totlen_t
00105 QuartzRecordTable::get_total_length() const
00106 {
00107 DEBUGCALL(DB, quartz_totlen_t, "QuartzRecordTable::get_total_length", "");
00108
00109 string tag;
00110 if (!get_exact_entry(METAINFO_KEY, tag)) RETURN(0);
00111
00112 Xapian::docid did;
00113 quartz_totlen_t totlen;
00114 const char * data = tag.data();
00115 const char * end = data + tag.size();
00116 if (!unpack_uint(&data, end, &did)) {
00117 throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
00118 }
00119 if (!unpack_uint_last(&data, end, &totlen)) {
00120 throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
00121 }
00122 RETURN(totlen);
00123 }
00124
00125 void
00126 QuartzRecordTable::delete_record(Xapian::docid did)
00127 {
00128 DEBUGCALL(DB, void, "QuartzRecordTable::delete_record", did);
00129 if (!del(quartz_docid_to_key(did)))
00130 throw Xapian::DocNotFoundError("Can't delete non-existent document #" + om_tostring(did));
00131 }