00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OM_HGUARD_OMENQUIREINTERNAL_H
00024 #define OM_HGUARD_OMENQUIREINTERNAL_H
00025
00026 #include <xapian/database.h>
00027 #include <xapian/document.h>
00028 #include <xapian/enquire.h>
00029 #include <xapian/sorter.h>
00030 #include <xapian/query.h>
00031 #include <algorithm>
00032 #include <math.h>
00033 #include <map>
00034 #include <set>
00035
00036 using namespace std;
00037
00038 class OmExpand;
00039 class RSetI;
00040 class MultiMatch;
00041
00042 namespace Xapian {
00043
00044 class ErrorHandler;
00045 class TermIterator;
00046
00047 namespace Internal {
00048
00053 class ESetItem {
00054 public:
00055 ESetItem(Xapian::weight wt_, string tname_) : wt(wt_), tname(tname_) { }
00056
00057 void swap(ESetItem & o) {
00058 std::swap(wt, o.wt);
00059 std::swap(tname, o.tname);
00060 }
00061
00063 Xapian::weight wt;
00065 string tname;
00066
00068 string get_description() const;
00069 };
00070
00075 class MSetItem {
00076 public:
00077 MSetItem(Xapian::weight wt_, Xapian::docid did_)
00078 : wt(wt_), did(did_), collapse_count(0) {}
00079
00080 MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_)
00081 : wt(wt_), did(did_), collapse_key(key_), collapse_count(0) {}
00082
00083 MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_,
00084 Xapian::doccount collapse_count_)
00085 : wt(wt_), did(did_), collapse_key(key_),
00086 collapse_count(collapse_count_) {}
00087
00088 void swap(MSetItem & o) {
00089 std::swap(wt, o.wt);
00090 std::swap(did, o.did);
00091 std::swap(collapse_key, o.collapse_key);
00092 std::swap(collapse_count, o.collapse_count);
00093 std::swap(sort_key, o.sort_key);
00094 }
00095
00097 Xapian::weight wt;
00098
00100 Xapian::docid did;
00101
00113 string collapse_key;
00114
00121 Xapian::doccount collapse_count;
00122
00124
00125 string sort_key;
00126
00128 string get_description() const;
00129 };
00130
00131 }
00132
00137 class Enquire::Internal : public Xapian::Internal::RefCntBase {
00138 private:
00140 const Xapian::Database db;
00141
00143 Query query;
00144
00146 termcount qlen;
00147
00149 Internal(const Internal &);
00151 void operator=(const Internal &);
00152
00153 public:
00154 typedef enum { REL, VAL, VAL_REL, REL_VAL } sort_setting;
00155
00156 Xapian::valueno collapse_key;
00157
00158 Xapian::Enquire::docid_order order;
00159
00160 percent percent_cutoff;
00161
00162 Xapian::weight weight_cutoff;
00163
00164 Xapian::valueno sort_key;
00165 sort_setting sort_by;
00166 bool sort_value_forward;
00167
00168 Sorter * sorter;
00169
00172 ErrorHandler * errorhandler;
00173
00179 mutable Weight * weight;
00180
00181 Internal(const Xapian::Database &databases, ErrorHandler * errorhandler_);
00182 ~Internal();
00183
00186 void request_doc(const Xapian::Internal::MSetItem &item) const;
00187
00190 Xapian::Document read_doc(const Xapian::Internal::MSetItem &item) const;
00191
00192 void set_query(const Query & query_, termcount qlen_);
00193 const Query & get_query();
00194 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00195 Xapian::doccount check_at_least,
00196 const RSet *omrset, const MatchDecider *mdecider,
00197 const MatchDecider *matchspy) const;
00198 ESet get_eset(Xapian::termcount maxitems, const RSet & omrset, int flags,
00199 double k, const ExpandDecider *edecider) const;
00200
00201 TermIterator get_matching_terms(Xapian::docid did) const;
00202 TermIterator get_matching_terms(const Xapian::MSetIterator &it) const;
00203
00204 void register_match_decider(const string &name,
00205 const MatchDecider *mdecider);
00206
00207 string get_description() const;
00208 };
00209
00210 class MSet::Internal : public Xapian::Internal::RefCntBase {
00211 public:
00213 double percent_factor;
00214
00215 private:
00219 mutable set<Xapian::doccount> requested_docs;
00220
00222 mutable map<Xapian::doccount, Xapian::Document> indexeddocs;
00223
00225 void read_docs() const;
00226
00228 Internal(const Internal &);
00230 void operator=(const Internal &);
00231
00232 public:
00234 Xapian::Internal::RefCntPtr<const Enquire::Internal> enquire;
00235
00239 struct TermFreqAndWeight {
00240 TermFreqAndWeight() { }
00241 TermFreqAndWeight(Xapian::doccount tf, Xapian::weight wt)
00242 : termfreq(tf), termweight(wt) { }
00243 Xapian::doccount termfreq;
00244 Xapian::weight termweight;
00245 };
00246
00252 map<string, TermFreqAndWeight> termfreqandwts;
00253
00255 vector<Xapian::Internal::MSetItem> items;
00256
00258 Xapian::doccount firstitem;
00259
00260 Xapian::doccount matches_lower_bound;
00261
00262 Xapian::doccount matches_estimated;
00263
00264 Xapian::doccount matches_upper_bound;
00265
00266 Xapian::weight max_possible;
00267
00268 Xapian::weight max_attained;
00269
00270 Internal()
00271 : percent_factor(0),
00272 firstitem(0),
00273 matches_lower_bound(0),
00274 matches_estimated(0),
00275 matches_upper_bound(0),
00276 max_possible(0),
00277 max_attained(0) {}
00278
00280 Internal(Xapian::doccount firstitem_,
00281 Xapian::doccount matches_upper_bound_,
00282 Xapian::doccount matches_lower_bound_,
00283 Xapian::doccount matches_estimated_,
00284 Xapian::weight max_possible_,
00285 Xapian::weight max_attained_,
00286 vector<Xapian::Internal::MSetItem> &items_,
00287 const map<string, TermFreqAndWeight> &termfreqandwts_,
00288 Xapian::weight percent_factor_)
00289 : percent_factor(percent_factor_),
00290 termfreqandwts(termfreqandwts_),
00291 firstitem(firstitem_),
00292 matches_lower_bound(matches_lower_bound_),
00293 matches_estimated(matches_estimated_),
00294 matches_upper_bound(matches_upper_bound_),
00295 max_possible(max_possible_),
00296 max_attained(max_attained_) {
00297 std::swap(items, items_);
00298 }
00299
00301 Xapian::Document get_doc_by_index(Xapian::doccount index) const;
00302
00304 percent convert_to_percent_internal(Xapian::weight wt) const;
00305
00307 string get_description() const;
00308
00311 void fetch_items(Xapian::doccount first, Xapian::doccount last) const;
00312 };
00313
00314 class ESet::Internal : public Xapian::Internal::RefCntBase {
00315 friend class ESet;
00316 friend class ESetIterator;
00317 friend class ::OmExpand;
00318 private:
00320 vector<Xapian::Internal::ESetItem> items;
00321
00326 Xapian::termcount ebound;
00327
00328 public:
00329 Internal() : ebound(0) {}
00330
00332 string get_description() const;
00333 };
00334
00335 class RSet::Internal : public Xapian::Internal::RefCntBase {
00336 friend class Xapian::RSet;
00337
00338 private:
00340 set<Xapian::docid> items;
00341
00342 public:
00343 const set<Xapian::docid> & get_items() const { return items; }
00344
00346 string get_description() const;
00347 };
00348
00349 }
00350
00351 #endif // OM_HGUARD_OMENQUIREINTERNAL_H