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 "xapian/postingsource.h"
00024 #include "xapian/error.h"
00025 #include "serialise.h"
00026 #include "serialise-double.h"
00027 #include <cmath>
00028
00029 using namespace Xapian;
00030
00031 DecreasingValueWeightPostingSource::DecreasingValueWeightPostingSource(
00032 Xapian::valueno slot_,
00033 Xapian::docid range_start_,
00034 Xapian::docid range_end_)
00035 : Xapian::ValueWeightPostingSource(slot_),
00036 range_start(range_start_),
00037 range_end(range_end_)
00038 {
00039 }
00040
00041 Xapian::weight
00042 DecreasingValueWeightPostingSource::get_weight() const {
00043 return curr_weight;
00044 }
00045
00046 Xapian::DecreasingValueWeightPostingSource *
00047 DecreasingValueWeightPostingSource::clone() const {
00048 return new DecreasingValueWeightPostingSource(slot, range_start,
00049 range_end);
00050 }
00051
00052 std::string
00053 DecreasingValueWeightPostingSource::name() const {
00054 return "Xapian::DecreasingValueWeightPostingSource";
00055 }
00056
00057 std::string
00058 DecreasingValueWeightPostingSource::serialise() const {
00059 std::string result;
00060 result += encode_length(slot);
00061 result += encode_length(range_start);
00062 result += encode_length(range_end);
00063 return result;
00064 }
00065
00066 Xapian::DecreasingValueWeightPostingSource *
00067 DecreasingValueWeightPostingSource::unserialise(const std::string &s) const {
00068 const char * pos = s.data();
00069 const char * end = pos + s.size();
00070 Xapian::valueno new_slot = decode_length(&pos, end, false);
00071 Xapian::docid new_range_start = decode_length(&pos, end, false);
00072 Xapian::docid new_range_end = decode_length(&pos, end, false);
00073 if (pos != end)
00074 throw Xapian::NetworkError("Junk at end of serialised "
00075 "DecreasingValueWeightPostingSource");
00076 return new DecreasingValueWeightPostingSource(new_slot, new_range_start,
00077 new_range_end);
00078 }
00079
00080 void
00081 DecreasingValueWeightPostingSource::init(const Xapian::Database & db_) {
00082 Xapian::ValueWeightPostingSource::init(db_);
00083 if (range_end == 0 || db.get_doccount() <= range_end)
00084 items_at_end = false;
00085 else
00086 items_at_end = true;
00087 }
00088
00089 void
00090 DecreasingValueWeightPostingSource::skip_if_in_range(Xapian::weight min_wt)
00091 {
00092 if (value_it == db.valuestream_end(slot)) return;
00093 curr_weight = Xapian::ValueWeightPostingSource::get_weight();
00094 Xapian::docid docid = Xapian::ValueWeightPostingSource::get_docid();
00095 if (docid >= range_start && (range_end == 0 || docid <= range_end)) {
00096 if (items_at_end) {
00097 if (curr_weight < min_wt) {
00098
00099 value_it.skip_to(range_end + 1);
00100 if (value_it != db.valuestream_end(slot))
00101 curr_weight = Xapian::ValueWeightPostingSource::get_weight();
00102 }
00103 } else {
00104 if (curr_weight < min_wt) {
00105
00106 value_it = db.valuestream_end(slot);
00107 } else {
00108
00109 set_maxweight(curr_weight);
00110 }
00111 }
00112 }
00113 }
00114
00115 void
00116 DecreasingValueWeightPostingSource::next(Xapian::weight min_wt) {
00117 if (get_maxweight() < min_wt) {
00118 value_it = db.valuestream_end(slot);
00119 started = true;
00120 return;
00121 }
00122 Xapian::ValueWeightPostingSource::next(min_wt);
00123 skip_if_in_range(min_wt);
00124 }
00125
00126 void
00127 DecreasingValueWeightPostingSource::skip_to(Xapian::docid min_docid,
00128 Xapian::weight min_wt) {
00129 if (get_maxweight() < min_wt) {
00130 value_it = db.valuestream_end(slot);
00131 started = true;
00132 return;
00133 }
00134 Xapian::ValueWeightPostingSource::skip_to(min_docid, min_wt);
00135 skip_if_in_range(min_wt);
00136 }
00137
00138 bool
00139 DecreasingValueWeightPostingSource::check(Xapian::docid min_docid,
00140 Xapian::weight min_wt) {
00141 if (get_maxweight() < min_wt) {
00142 value_it = db.valuestream_end(slot);
00143 started = true;
00144 return true;
00145 }
00146 bool valid = Xapian::ValueWeightPostingSource::check(min_docid, min_wt);
00147 if (valid) {
00148 skip_if_in_range(min_wt);
00149 }
00150 return valid;
00151 }
00152
00153 std::string
00154 DecreasingValueWeightPostingSource::get_description() const {
00155 return "DecreasingValueWeightPostingSource()";
00156 }