00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OM_HGUARD_QUARTZ_ALLDOCSPOSTLIST_H
00025 #define OM_HGUARD_QUARTZ_ALLDOCSPOSTLIST_H
00026
00027 #include <map>
00028 #include <string>
00029
00030 #include "leafpostlist.h"
00031 #include <xapian/database.h>
00032 #include <xapian/postingiterator.h>
00033 #include "database.h"
00034 #include "omassert.h"
00035 #include "quartz_types.h"
00036 #include "btree.h"
00037
00038 using namespace std;
00039
00040 class Bcursor;
00041
00042 class QuartzDocIdList;
00043
00044 class QuartzDocIdListIterator {
00045 private:
00046 const map<Xapian::docid, Xapian::docid> * ranges;
00047 map<Xapian::docid, Xapian::docid>::const_iterator currrange;
00048 Xapian::docid currdocid;
00049
00050 friend class QuartzDocIdList;
00051
00052 QuartzDocIdListIterator(const map<Xapian::docid, Xapian::docid> * ranges_);
00053 QuartzDocIdListIterator(const map<Xapian::docid, Xapian::docid> * ranges_, int);
00054
00055 public:
00056 Xapian::docid operator*() {
00057 return currdocid;
00058 }
00059
00060 friend bool operator==(const QuartzDocIdListIterator &a,
00061 const QuartzDocIdListIterator &b);
00062
00063 QuartzDocIdListIterator();
00064 ~QuartzDocIdListIterator() {}
00065 QuartzDocIdListIterator(const QuartzDocIdListIterator & other);
00066 void operator=(const QuartzDocIdListIterator & other);
00067
00068 QuartzDocIdListIterator & operator++();
00069
00070 Xapian::DocIDWrapper operator++(int) {
00071 Xapian::docid tmp = **this;
00072 operator++();
00073 return Xapian::DocIDWrapper(tmp);
00074 }
00075
00076 Xapian::docid operator *() const { return currdocid; }
00077
00079
00080 typedef std::input_iterator_tag iterator_category;
00081 typedef Xapian::docid value_type;
00082 typedef Xapian::doccount_diff difference_type;
00083 typedef Xapian::docid * pointer;
00084 typedef Xapian::docid & reference;
00086 };
00087
00088 inline bool operator==(const QuartzDocIdListIterator &a,
00089 const QuartzDocIdListIterator &b)
00090 {
00091 if (a.ranges != b.ranges)
00092 return false;
00093 return a.currdocid == b.currdocid;
00094 }
00095
00096 inline bool operator!=(const QuartzDocIdListIterator &a,
00097 const QuartzDocIdListIterator &b)
00098 {
00099 return !(a==b);
00100 }
00101
00102 class QuartzDocIdList {
00103 private:
00106 map<Xapian::docid, Xapian::docid> ranges;
00107
00108 public:
00109 QuartzDocIdList() {}
00110 void addDocId(Xapian::docid did);
00111
00112 QuartzDocIdListIterator begin() const {
00113 return QuartzDocIdListIterator(&ranges);
00114 }
00115
00116 QuartzDocIdListIterator end() const {
00117 return QuartzDocIdListIterator(&ranges, 1);
00118 }
00119 };
00120
00123 class QuartzAllDocsPostList : public LeafPostList {
00124 private:
00126 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> this_db;
00127
00129 QuartzDocIdList docids;
00130
00132 QuartzDocIdListIterator dociditer;
00133
00135 Xapian::doccount doccount;
00136
00138 bool have_started;
00139
00141 QuartzAllDocsPostList(const QuartzAllDocsPostList &);
00142
00144 void operator=(const QuartzAllDocsPostList &);
00145
00146 public:
00148 QuartzAllDocsPostList(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> this_db_,
00149 const Btree * table,
00150 Xapian::doccount doccount_);
00151
00153 ~QuartzAllDocsPostList();
00154
00159 Xapian::doccount get_termfreq() const { return doccount; }
00160
00162 Xapian::docid get_docid() const {
00163 Assert(have_started);
00164 return *dociditer;
00165 }
00166
00168 Xapian::doclength get_doclength() const {
00169 Assert(have_started);
00170 return this_db->get_doclength(*dociditer);
00171 }
00172
00176 Xapian::termcount get_wdf() const {
00177 Assert(have_started);
00178 return static_cast<Xapian::termcount>(1);
00179 }
00180
00183 PositionList *read_position_list() {
00184 throw Xapian::InvalidOperationError("Can't read position list from all docs postlist.");
00185 }
00186
00189 PositionList * open_position_list() const {
00190 throw Xapian::InvalidOperationError("Can't read position list from all docs postlist.");
00191 }
00192
00194 PostList * next(Xapian::weight w_min);
00195
00197 PostList * skip_to(Xapian::docid desired_did, Xapian::weight w_min);
00198
00200 bool at_end() const { return (have_started && dociditer == docids.end()); }
00201
00203 std::string get_description() const;
00204 };
00205
00206 #endif