00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef OM_HGUARD_OMENQUIREINTERNAL_H
00026 #define OM_HGUARD_OMENQUIREINTERNAL_H
00027
00028 #include "xapian/database.h"
00029 #include "xapian/document.h"
00030 #include "xapian/enquire.h"
00031 #include "xapian/query.h"
00032 #include "xapian/keymaker.h"
00033
00034 #include <algorithm>
00035 #include <cmath>
00036 #include <map>
00037 #include <set>
00038
00039 using namespace std;
00040
00041 class OmExpand;
00042 class MultiMatch;
00043
00044 namespace Xapian {
00045
00046 class ErrorHandler;
00047 class TermIterator;
00048
00049 namespace Internal {
00050
00055 class MSetItem {
00056 public:
00057 MSetItem(Xapian::weight wt_, Xapian::docid did_)
00058 : wt(wt_), did(did_), collapse_count(0) {}
00059
00060 MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_)
00061 : wt(wt_), did(did_), collapse_key(key_), collapse_count(0) {}
00062
00063 MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_,
00064 Xapian::doccount collapse_count_)
00065 : wt(wt_), did(did_), collapse_key(key_),
00066 collapse_count(collapse_count_) {}
00067
00068 void swap(MSetItem & o) {
00069 std::swap(wt, o.wt);
00070 std::swap(did, o.did);
00071 std::swap(collapse_key, o.collapse_key);
00072 std::swap(collapse_count, o.collapse_count);
00073 std::swap(sort_key, o.sort_key);
00074 }
00075
00077 Xapian::weight wt;
00078
00080 Xapian::docid did;
00081
00093 string collapse_key;
00094
00101 Xapian::doccount collapse_count;
00102
00104 string sort_key;
00105
00107 string get_description() const;
00108 };
00109
00110 }
00111
00116 class Enquire::Internal : public Xapian::Internal::RefCntBase {
00117 private:
00119 const Xapian::Database db;
00120
00122 Query query;
00123
00125 termcount qlen;
00126
00128 Internal(const Internal &);
00130 void operator=(const Internal &);
00131
00132 public:
00133 typedef enum { REL, VAL, VAL_REL, REL_VAL } sort_setting;
00134
00135 Xapian::valueno collapse_key;
00136
00137 Xapian::doccount collapse_max;
00138
00139 Xapian::Enquire::docid_order order;
00140
00141 percent percent_cutoff;
00142
00143 Xapian::weight weight_cutoff;
00144
00145 Xapian::valueno sort_key;
00146 sort_setting sort_by;
00147 bool sort_value_forward;
00148
00149 KeyMaker * sorter;
00150
00153 ErrorHandler * errorhandler;
00154
00160 mutable Weight * weight;
00161
00162 vector<MatchSpy *> spies;
00163
00164 Internal(const Xapian::Database &databases, ErrorHandler * errorhandler_);
00165 ~Internal();
00166
00169 void request_doc(const Xapian::Internal::MSetItem &item) const;
00170
00173 Xapian::Document read_doc(const Xapian::Internal::MSetItem &item) const;
00174
00175 void set_query(const Query & query_, termcount qlen_);
00176 const Query & get_query();
00177 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00178 Xapian::doccount check_at_least,
00179 const RSet *omrset,
00180 const MatchDecider *mdecider,
00181 const MatchDecider *matchspy_legacy) const;
00182
00183 ESet get_eset(Xapian::termcount maxitems, const RSet & omrset, int flags,
00184 double k, const ExpandDecider *edecider, Xapian::weight min_wt) const;
00185
00186 TermIterator get_matching_terms(Xapian::docid did) const;
00187 TermIterator get_matching_terms(const Xapian::MSetIterator &it) const;
00188
00189 Xapian::doccount get_termfreq(const string &tname) const;
00190
00191 string get_description() const;
00192 };
00193
00194 class MSet::Internal : public Xapian::Internal::RefCntBase {
00195 public:
00197 double percent_factor;
00198
00199 private:
00203 mutable set<Xapian::doccount> requested_docs;
00204
00206 mutable map<Xapian::doccount, Xapian::Document> indexeddocs;
00207
00209 void read_docs() const;
00210
00212 Internal(const Internal &);
00214 void operator=(const Internal &);
00215
00216 public:
00218 Xapian::Internal::RefCntPtr<const Enquire::Internal> enquire;
00219
00223 struct TermFreqAndWeight {
00224 TermFreqAndWeight() { }
00225 explicit TermFreqAndWeight(Xapian::doccount tf)
00226 : termfreq(tf), termweight(0.0) { }
00227 TermFreqAndWeight(Xapian::doccount tf, Xapian::weight wt)
00228 : termfreq(tf), termweight(wt) { }
00229 Xapian::doccount termfreq;
00230 Xapian::weight termweight;
00231 };
00232
00238 map<string, TermFreqAndWeight> termfreqandwts;
00239
00241 vector<Xapian::Internal::MSetItem> items;
00242
00244 Xapian::doccount firstitem;
00245
00246 Xapian::doccount matches_lower_bound;
00247
00248 Xapian::doccount matches_estimated;
00249
00250 Xapian::doccount matches_upper_bound;
00251
00252 Xapian::doccount uncollapsed_lower_bound;
00253
00254 Xapian::doccount uncollapsed_estimated;
00255
00256 Xapian::doccount uncollapsed_upper_bound;
00257
00258 Xapian::weight max_possible;
00259
00260 Xapian::weight max_attained;
00261
00262 Internal()
00263 : percent_factor(0),
00264 firstitem(0),
00265 matches_lower_bound(0),
00266 matches_estimated(0),
00267 matches_upper_bound(0),
00268 uncollapsed_lower_bound(0),
00269 uncollapsed_estimated(0),
00270 uncollapsed_upper_bound(0),
00271 max_possible(0),
00272 max_attained(0) {}
00273
00275 Internal(Xapian::doccount firstitem_,
00276 Xapian::doccount matches_upper_bound_,
00277 Xapian::doccount matches_lower_bound_,
00278 Xapian::doccount matches_estimated_,
00279 Xapian::doccount uncollapsed_upper_bound_,
00280 Xapian::doccount uncollapsed_lower_bound_,
00281 Xapian::doccount uncollapsed_estimated_,
00282 Xapian::weight max_possible_,
00283 Xapian::weight max_attained_,
00284 vector<Xapian::Internal::MSetItem> &items_,
00285 const map<string, TermFreqAndWeight> &termfreqandwts_,
00286 Xapian::weight percent_factor_)
00287 : percent_factor(percent_factor_),
00288 termfreqandwts(termfreqandwts_),
00289 firstitem(firstitem_),
00290 matches_lower_bound(matches_lower_bound_),
00291 matches_estimated(matches_estimated_),
00292 matches_upper_bound(matches_upper_bound_),
00293 uncollapsed_lower_bound(uncollapsed_lower_bound_),
00294 uncollapsed_estimated(uncollapsed_estimated_),
00295 uncollapsed_upper_bound(uncollapsed_upper_bound_),
00296 max_possible(max_possible_),
00297 max_attained(max_attained_) {
00298 std::swap(items, items_);
00299 }
00300
00302 Xapian::Document get_doc_by_index(Xapian::doccount index) const;
00303
00305 percent convert_to_percent_internal(Xapian::weight wt) const;
00306
00308 string get_description() const;
00309
00312 void fetch_items(Xapian::doccount first, Xapian::doccount last) const;
00313 };
00314
00315 class RSet::Internal : public Xapian::Internal::RefCntBase {
00316 friend class Xapian::RSet;
00317
00318 private:
00320 set<Xapian::docid> items;
00321
00322 public:
00323 const set<Xapian::docid> & get_items() const { return items; }
00324
00326 string get_description() const;
00327 };
00328
00329 }
00330
00331 #endif // OM_HGUARD_OMENQUIREINTERNAL_H