00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "brass_termlisttable.h"
00024
00025 #include <xapian/document.h>
00026 #include <xapian/error.h>
00027 #include <xapian/termiterator.h>
00028
00029 #include "debuglog.h"
00030 #include "omassert.h"
00031 #include "pack.h"
00032 #include "stringutils.h"
00033 #include "utils.h"
00034
00035 #include <string>
00036
00037 using namespace std;
00038
00039 void
00040 BrassTermListTable::set_termlist(Xapian::docid did,
00041 const Xapian::Document & doc,
00042 brass_doclen_t doclen)
00043 {
00044 LOGCALL_VOID(DB, "BrassTermListTable::set_termlist", did | doc | doclen);
00045
00046 string tag;
00047 pack_uint(tag, doclen);
00048
00049 Xapian::doccount termlist_size = doc.termlist_count();
00050 if (termlist_size == 0) {
00051
00052 Assert(doclen == 0);
00053 Assert(doc.termlist_begin() == doc.termlist_end());
00054 add(make_key(did), string());
00055 return;
00056 }
00057
00058 Xapian::TermIterator t = doc.termlist_begin();
00059 if (t != doc.termlist_end()) {
00060 pack_uint(tag, termlist_size);
00061 string prev_term = *t;
00062
00063 tag += prev_term.size();
00064 tag += prev_term;
00065 pack_uint(tag, t.get_wdf());
00066 --termlist_size;
00067
00068 while (++t != doc.termlist_end()) {
00069 const string & term = *t;
00070
00071
00072
00073 size_t reuse = common_prefix_length(prev_term, term);
00074
00075
00076
00077
00078
00079
00080
00081
00082 size_t packed = 0;
00083 Xapian::termcount wdf = t.get_wdf();
00084
00085
00086
00087 if (wdf < 127)
00088 packed = (wdf + 1) * (prev_term.size() + 1) + reuse;
00089
00090 if (packed && packed < 256) {
00091
00092 tag += char(packed);
00093 tag += char(term.size() - reuse);
00094 tag.append(term.data() + reuse, term.size() - reuse);
00095 } else {
00096 tag += char(reuse);
00097 tag += char(term.size() - reuse);
00098 tag.append(term.data() + reuse, term.size() - reuse);
00099
00100
00101 pack_uint(tag, wdf);
00102 }
00103
00104 prev_term = *t;
00105 --termlist_size;
00106 }
00107 }
00108 Assert(termlist_size == 0);
00109 add(make_key(did), tag);
00110 }