00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "flint_alltermslist.h"
00024 #include "flint_postlist.h"
00025 #include "flint_utils.h"
00026
00027 #include "stringutils.h"
00028
00029 void
00030 FlintAllTermsList::read_termfreq_and_collfreq() const
00031 {
00032 DEBUGCALL(DB, void, "FlintAllTermsList::read_termfreq_and_collfreq", "");
00033 Assert(!current_term.empty());
00034 Assert(!at_end());
00035
00036
00037
00038 cursor->read_tag();
00039 const char *p = cursor->current_tag.data();
00040 const char *pend = p + cursor->current_tag.size();
00041 FlintPostList::read_number_of_entries(&p, pend, &termfreq, &collfreq);
00042 }
00043
00044 FlintAllTermsList::~FlintAllTermsList()
00045 {
00046 DEBUGCALL(DB, void, "~FlintAllTermsList", "");
00047 delete cursor;
00048 }
00049
00050 string
00051 FlintAllTermsList::get_termname() const
00052 {
00053 DEBUGCALL(DB, string, "FlintAllTermsList::get_termname", "");
00054 Assert(!current_term.empty());
00055 Assert(!at_end());
00056 RETURN(current_term);
00057 }
00058
00059 Xapian::doccount
00060 FlintAllTermsList::get_termfreq() const
00061 {
00062 DEBUGCALL(DB, Xapian::doccount, "FlintAllTermsList::get_termfreq", "");
00063 Assert(!current_term.empty());
00064 Assert(!at_end());
00065 if (termfreq == 0) read_termfreq_and_collfreq();
00066 RETURN(termfreq);
00067 }
00068
00069 Xapian::termcount
00070 FlintAllTermsList::get_collection_freq() const
00071 {
00072 DEBUGCALL(DB, Xapian::termcount, "FlintAllTermsList::get_collection_freq", "");
00073 Assert(!current_term.empty());
00074 Assert(!at_end());
00075 if (termfreq == 0) read_termfreq_and_collfreq();
00076 RETURN(collfreq);
00077 }
00078
00079 TermList *
00080 FlintAllTermsList::next()
00081 {
00082 DEBUGCALL(DB, TermList *, "FlintAllTermsList::next", "");
00083 Assert(!at_end());
00084
00085
00086 termfreq = 0;
00087
00088 while (true) {
00089 cursor->next();
00090 if (cursor->after_end()) {
00091 current_term = "";
00092 break;
00093 }
00094
00095 const char *p = cursor->current_key.data();
00096 const char *pend = p + cursor->current_key.size();
00097 if (!unpack_string_preserving_sort(&p, pend, current_term)) {
00098 throw Xapian::DatabaseCorruptError("PostList table key has unexpected format");
00099 }
00100
00101 if (!startswith(current_term, prefix)) {
00102
00103 cursor->to_end();
00104 current_term = "";
00105 break;
00106 }
00107
00108
00109
00110
00111 if (p == pend) break;
00112 }
00113 RETURN(NULL);
00114 }
00115
00116 TermList *
00117 FlintAllTermsList::skip_to(const string &term)
00118 {
00119 DEBUGCALL(DB, TermList *, "FlintAllTermsList::skip_to", term);
00120 Assert(!at_end());
00121
00122
00123 termfreq = 0;
00124
00125 if (cursor->find_entry_ge(pack_string_preserving_sort(term))) {
00126
00127
00128 current_term = term;
00129 } else {
00130 if (cursor->after_end()) {
00131 current_term = "";
00132 RETURN(NULL);
00133 }
00134
00135 const char *p = cursor->current_key.data();
00136 const char *pend = p + cursor->current_key.size();
00137 if (!unpack_string_preserving_sort(&p, pend, current_term)) {
00138 throw Xapian::DatabaseCorruptError("PostList table key has unexpected format");
00139 }
00140 }
00141
00142 if (!startswith(current_term, prefix)) {
00143
00144 cursor->to_end();
00145 current_term = "";
00146 }
00147
00148 RETURN(NULL);
00149 }
00150
00151 bool
00152 FlintAllTermsList::at_end() const
00153 {
00154 DEBUGCALL(DB, bool, "FlintAllTermsList::at_end", "");
00155 RETURN(cursor->after_end());
00156 }