00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023 #include "chert_metadata.h"
00024
00025 #include "database.h"
00026 #include "debuglog.h"
00027 #include "omassert.h"
00028 #include "stringutils.h"
00029
00030 using namespace std;
00031
00032 ChertMetadataTermList::ChertMetadataTermList(
00033 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
00034 ChertCursor * cursor_,
00035 const string &prefix_)
00036 : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
00037 {
00038 LOGCALL_CTOR(DB, "ChertMetadataTermList", database_ | cursor_ | prefix_);
00039 Assert(cursor);
00040
00041 cursor->find_entry_lt(prefix);
00042 }
00043
00044 ChertMetadataTermList::~ChertMetadataTermList()
00045 {
00046 LOGCALL_DTOR(DB, "ChertMetadataTermList");
00047 delete cursor;
00048 }
00049
00050 string
00051 ChertMetadataTermList::get_termname() const
00052 {
00053 LOGCALL(DB, string, "ChertMetadataTermList::get_termname", NO_ARGS);
00054 Assert(!at_end());
00055 Assert(!cursor->current_key.empty());
00056 Assert(startswith(cursor->current_key, prefix));
00057 RETURN(cursor->current_key.substr(2));
00058 }
00059
00060 Xapian::doccount
00061 ChertMetadataTermList::get_termfreq() const
00062 {
00063 throw Xapian::InvalidOperationError("ChertMetadataTermList::get_termfreq() not meaningful");
00064 }
00065
00066 Xapian::termcount
00067 ChertMetadataTermList::get_collection_freq() const
00068 {
00069 throw Xapian::InvalidOperationError("ChertMetadataTermList::get_collection_freq() not meaningful");
00070 }
00071
00072 TermList *
00073 ChertMetadataTermList::next()
00074 {
00075 LOGCALL(DB, TermList *, "ChertMetadataTermList::next", NO_ARGS);
00076 Assert(!at_end());
00077
00078 cursor->next();
00079 if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
00080
00081 cursor->to_end();
00082 }
00083
00084 RETURN(NULL);
00085 }
00086
00087 TermList *
00088 ChertMetadataTermList::skip_to(const string &key)
00089 {
00090 LOGCALL(DB, TermList *, "ChertMetadataTermList::skip_to", key);
00091 Assert(!at_end());
00092
00093 if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
00094
00095
00096 if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
00097
00098 cursor->to_end();
00099 }
00100 }
00101 RETURN(NULL);
00102 }
00103
00104 bool
00105 ChertMetadataTermList::at_end() const
00106 {
00107 LOGCALL(DB, bool, "ChertMetadataTermList::at_end", NO_ARGS);
00108 RETURN(cursor->after_end());
00109 }