00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <config.h>
00024 #include "quartz_values.h"
00025 #include "quartz_utils.h"
00026 #include "utils.h"
00027 #include <xapian/error.h>
00028 using std::string;
00029 using std::make_pair;
00030
00031 #include "omdebug.h"
00032
00034 inline void
00035 make_key(string & key, Xapian::docid did)
00036 {
00037 DEBUGCALL_STATIC(DB, void, "make_key", key << ", " << did);
00038 key = quartz_docid_to_key(did);
00039 }
00040
00041 void
00042 QuartzValueTable::unpack_entry(const char ** pos,
00043 const char * end,
00044 Xapian::valueno * this_value_no,
00045 string & this_value)
00046 {
00047 DEBUGCALL_STATIC(DB, void, "QuartzValueTable::unpack_entry",
00048 "[pos], [end], " << this_value_no << ", " << this_value);
00049 if (!unpack_uint(pos, end, this_value_no)) {
00050 if (*pos == 0) throw Xapian::DatabaseCorruptError("Incomplete item in value table");
00051 else throw Xapian::RangeError("Value number in value table is too large");
00052 }
00053
00054 if (!unpack_string(pos, end, this_value)) {
00055 if (*pos == 0) throw Xapian::DatabaseCorruptError("Incomplete item in value table");
00056 else throw Xapian::RangeError("Item in value table is too large");
00057 }
00058
00059 DEBUGLINE(DB, "QuartzValueTable::unpack_entry(): value no " <<
00060 this_value_no << " is `" << this_value << "'");
00061 }
00062
00063 void
00064 QuartzValueTable::encode_values(string & s,
00065 Xapian::ValueIterator it,
00066 const Xapian::ValueIterator & end)
00067 {
00068 DEBUGCALL(DB, void, "QuartzValueTable::encode_values", "[&s], " << it << ", " << end);
00069 while (it != end) {
00070 s += pack_uint(it.get_valueno());
00071 s += pack_string(*it);
00072 ++it;
00073 }
00074 }
00075
00076 void
00077 QuartzValueTable::set_encoded_values(Xapian::docid did, const string & enc)
00078 {
00079 DEBUGCALL(DB, void, "QuartzValueTable::set_encoded_values", did << ", " << enc);
00080 string key;
00081 make_key(key, did);
00082 add(key, enc);
00083 }
00084
00085 void
00086 QuartzValueTable::get_value(string & value,
00087 Xapian::docid did,
00088 Xapian::valueno valueno) const
00089 {
00090 DEBUGCALL(DB, void, "QuartzValueTable::get_value", value << ", " << did << ", " << valueno);
00091 string key;
00092 make_key(key, did);
00093 string tag;
00094 bool found = get_exact_entry(key, tag);
00095
00096 if (found) {
00097 const char * pos = tag.data();
00098 const char * end = pos + tag.size();
00099
00100 while (pos && pos != end) {
00101 Xapian::valueno this_value_no;
00102 string this_value;
00103
00104 unpack_entry(&pos, end, &this_value_no, this_value);
00105
00106 if (this_value_no == valueno) {
00107 value = this_value;
00108 return;
00109 }
00110
00111
00112 if (this_value_no > valueno) break;
00113 }
00114 }
00115 value = "";
00116 }
00117
00118 void
00119 QuartzValueTable::get_all_values(map<Xapian::valueno, string> & values,
00120 Xapian::docid did) const
00121 {
00122 DEBUGCALL(DB, void, "QuartzValueTable::get_all_values", "[values], " << did);
00123 string key;
00124 make_key(key, did);
00125 string tag;
00126 bool found = get_exact_entry(key, tag);
00127
00128 values.clear();
00129 if (!found) return;
00130
00131 const char * pos = tag.data();
00132 const char * end = pos + tag.size();
00133
00134 while (pos && pos != end) {
00135 Xapian::valueno this_value_no;
00136 string this_value;
00137
00138 unpack_entry(&pos, end, &this_value_no, this_value);
00139 values.insert(make_pair(this_value_no, this_value));
00140 }
00141 }
00142
00143 void
00144 QuartzValueTable::delete_all_values(Xapian::docid did)
00145 {
00146 DEBUGCALL(DB, void, "QuartzValueTable::delete_all_values", did);
00147 string key;
00148 make_key(key, did);
00149 del(key);
00150 }