00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef XAPIAN_INCLUDED_ENQUIRE_H
00025 #define XAPIAN_INCLUDED_ENQUIRE_H
00026
00027 #include <string>
00028
00029 #include <xapian/base.h>
00030 #include <xapian/deprecated.h>
00031 #include <xapian/error.h>
00032 #include <xapian/types.h>
00033 #include <xapian/termiterator.h>
00034 #include <xapian/visibility.h>
00035
00036 namespace Xapian {
00037
00038 class Database;
00039 class Document;
00040 class ErrorHandler;
00041 class ExpandDecider;
00042 class MSetIterator;
00043 class Query;
00044 class Weight;
00045
00049 class XAPIAN_VISIBILITY_DEFAULT MSet {
00050 public:
00051 class Internal;
00053 Xapian::Internal::RefCntPtr<Internal> internal;
00054
00056 explicit MSet(MSet::Internal * internal_);
00057
00059 MSet();
00060
00062 ~MSet();
00063
00065 MSet(const MSet & other);
00066
00068 void operator=(const MSet &other);
00069
00085 void fetch(const MSetIterator &begin, const MSetIterator &end) const;
00086
00089 void fetch(const MSetIterator &item) const;
00090
00093 void fetch() const;
00094
00099 Xapian::percent convert_to_percent(Xapian::weight wt) const;
00100
00102 Xapian::percent convert_to_percent(const MSetIterator &it) const;
00103
00111 Xapian::doccount get_termfreq(const std::string &tname) const;
00112
00120 Xapian::weight get_termweight(const std::string &tname) const;
00121
00129 Xapian::doccount get_firstitem() const;
00130
00140 Xapian::doccount get_matches_lower_bound() const;
00141
00154 Xapian::doccount get_matches_estimated() const;
00155
00165 Xapian::doccount get_matches_upper_bound() const;
00166
00172 Xapian::weight get_max_possible() const;
00173
00187 Xapian::weight get_max_attained() const;
00188
00190 Xapian::doccount size() const;
00191
00193 Xapian::doccount max_size() const { return size(); }
00194
00196 bool empty() const;
00197
00199 void swap(MSet & other);
00200
00202 MSetIterator begin() const;
00203
00205 MSetIterator end() const;
00206
00208 MSetIterator back() const;
00209
00219 MSetIterator operator[](Xapian::doccount i) const;
00220
00222
00223 typedef MSetIterator value_type;
00224 typedef MSetIterator iterator;
00225 typedef MSetIterator const_iterator;
00226 typedef MSetIterator & reference;
00227 typedef MSetIterator & const_reference;
00228 typedef MSetIterator * pointer;
00229 typedef Xapian::doccount_diff difference_type;
00230 typedef Xapian::doccount size_type;
00232
00236 std::string get_description() const;
00237 };
00238
00242 class XAPIAN_VISIBILITY_DEFAULT MSetIterator {
00243 private:
00244 friend class MSet;
00245 friend bool operator==(const MSetIterator &a, const MSetIterator &b);
00246 friend bool operator!=(const MSetIterator &a, const MSetIterator &b);
00247
00248 MSetIterator(Xapian::doccount index_, const MSet & mset_)
00249 : index(index_), mset(mset_) { }
00250
00251 Xapian::doccount index;
00252 MSet mset;
00253
00254 public:
00258 MSetIterator() : index(0), mset() { }
00259
00260 ~MSetIterator() { }
00261
00263 MSetIterator(const MSetIterator &other) {
00264 index = other.index;
00265 mset = other.mset;
00266 }
00267
00269 void operator=(const MSetIterator &other) {
00270 index = other.index;
00271 mset = other.mset;
00272 }
00273
00275 MSetIterator & operator++() {
00276 ++index;
00277 return *this;
00278 }
00279
00281 MSetIterator operator++(int) {
00282 MSetIterator tmp = *this;
00283 ++index;
00284 return tmp;
00285 }
00286
00288 MSetIterator & operator--() {
00289 --index;
00290 return *this;
00291 }
00292
00294 MSetIterator operator--(int) {
00295 MSetIterator tmp = *this;
00296 --index;
00297 return tmp;
00298 }
00299
00301 Xapian::docid operator*() const;
00302
00319 Xapian::Document get_document() const;
00320
00327 Xapian::doccount get_rank() const {
00328 return mset.get_firstitem() + index;
00329 }
00330
00332 Xapian::weight get_weight() const;
00333
00336 std::string get_collapse_key() const;
00337
00354 Xapian::doccount get_collapse_count() const;
00355
00361 Xapian::percent get_percent() const;
00362
00366 std::string get_description() const;
00367
00369
00370 typedef std::bidirectional_iterator_tag iterator_category;
00371 typedef Xapian::docid value_type;
00372 typedef Xapian::doccount_diff difference_type;
00373 typedef Xapian::docid * pointer;
00374 typedef Xapian::docid & reference;
00376 };
00377
00378 inline bool operator==(const MSetIterator &a, const MSetIterator &b)
00379 {
00380 return (a.index == b.index);
00381 }
00382
00383 inline bool operator!=(const MSetIterator &a, const MSetIterator &b)
00384 {
00385 return (a.index != b.index);
00386 }
00387
00388 class ESetIterator;
00389
00394 class XAPIAN_VISIBILITY_DEFAULT ESet {
00395 public:
00396 class Internal;
00398 Xapian::Internal::RefCntPtr<Internal> internal;
00399
00401 ESet();
00402
00404 ~ESet();
00405
00407 ESet(const ESet & other);
00408
00410 void operator=(const ESet &other);
00411
00416 Xapian::termcount get_ebound() const;
00417
00419 Xapian::termcount size() const;
00420
00422 Xapian::termcount max_size() const { return size(); }
00423
00425 bool empty() const;
00426
00428 void swap(ESet & other);
00429
00431 ESetIterator begin() const;
00432
00434 ESetIterator end() const;
00435
00437 ESetIterator back() const;
00438
00440 ESetIterator operator[](Xapian::termcount i) const;
00441
00446 std::string get_description() const;
00447 };
00448
00450 class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
00451 private:
00452 friend class ESet;
00453 friend bool operator==(const ESetIterator &a, const ESetIterator &b);
00454 friend bool operator!=(const ESetIterator &a, const ESetIterator &b);
00455
00456 ESetIterator(Xapian::termcount index_, const ESet & eset_)
00457 : index(index_), eset(eset_) { }
00458
00459 Xapian::termcount index;
00460 ESet eset;
00461
00462 public:
00466 ESetIterator() : index(0), eset() { }
00467
00468 ~ESetIterator() { }
00469
00471 ESetIterator(const ESetIterator &other) {
00472 index = other.index;
00473 eset = other.eset;
00474 }
00475
00477 void operator=(const ESetIterator &other) {
00478 index = other.index;
00479 eset = other.eset;
00480 }
00481
00483 ESetIterator & operator++() {
00484 ++index;
00485 return *this;
00486 }
00487
00489 ESetIterator operator++(int) {
00490 ESetIterator tmp = *this;
00491 ++index;
00492 return tmp;
00493 }
00494
00496 ESetIterator & operator--() {
00497 --index;
00498 return *this;
00499 }
00500
00502 ESetIterator operator--(int) {
00503 ESetIterator tmp = *this;
00504 --index;
00505 return tmp;
00506 }
00507
00509 const std::string & operator *() const;
00510
00512 Xapian::weight get_weight() const;
00513
00517 std::string get_description() const;
00518
00520
00521 typedef std::bidirectional_iterator_tag iterator_category;
00522 typedef std::string value_type;
00523 typedef Xapian::termcount_diff difference_type;
00524 typedef std::string * pointer;
00525 typedef std::string & reference;
00527 };
00528
00529 inline bool operator==(const ESetIterator &a, const ESetIterator &b)
00530 {
00531 return (a.index == b.index);
00532 }
00533
00534 inline bool operator!=(const ESetIterator &a, const ESetIterator &b)
00535 {
00536 return (a.index != b.index);
00537 }
00538
00543 class XAPIAN_VISIBILITY_DEFAULT RSet {
00544 public:
00546 class Internal;
00547
00549 Xapian::Internal::RefCntPtr<Internal> internal;
00550
00552 RSet(const RSet &rset);
00553
00555 void operator=(const RSet &rset);
00556
00558 RSet();
00559
00561 ~RSet();
00562
00564 Xapian::doccount size() const;
00565
00567 bool empty() const;
00568
00570 void add_document(Xapian::docid did);
00571
00573 void add_document(const Xapian::MSetIterator & i) { add_document(*i); }
00574
00576 void remove_document(Xapian::docid did);
00577
00579 void remove_document(const Xapian::MSetIterator & i) { remove_document(*i); }
00580
00582 bool contains(Xapian::docid did) const;
00583
00585 bool contains(const Xapian::MSetIterator & i) const { return contains(*i); }
00586
00591 std::string get_description() const;
00592 };
00593
00596 class XAPIAN_VISIBILITY_DEFAULT MatchDecider {
00597 public:
00600 virtual bool operator()(const Xapian::Document &doc) const = 0;
00601
00603 virtual ~MatchDecider();
00604 };
00605
00616 class XAPIAN_VISIBILITY_DEFAULT Enquire {
00617 private:
00619 Enquire(const Enquire &);
00620
00622 void operator=(const Enquire &);
00623
00624 public:
00625 class Internal;
00627 Xapian::Internal::RefCntPtr<Internal> internal;
00628
00644 explicit Enquire(const Database &database, ErrorHandler * errorhandler_ = 0);
00645
00648 ~Enquire();
00649
00656 void set_query(const Xapian::Query & query, Xapian::termcount qlen = 0);
00657
00664 const Xapian::Query & get_query() const;
00665
00672 void set_weighting_scheme(const Weight &weight_);
00673
00700 void set_collapse_key(Xapian::valueno collapse_key);
00701
00702 typedef enum {
00703 ASCENDING = 1,
00704 DESCENDING = 0,
00705 DONT_CARE = 2
00706 } docid_order;
00707
00731 void set_docid_order(docid_order order);
00732
00751 void set_cutoff(Xapian::percent percent_cutoff, Xapian::weight weight_cutoff = 0);
00752
00757 void set_sort_by_relevance();
00758
00771 void set_sort_by_value(Xapian::valueno sort_key, bool ascending = true);
00772
00786 void set_sort_by_value_then_relevance(Xapian::valueno sort_key,
00787 bool ascending = true);
00788
00808 void set_sort_by_relevance_then_value(Xapian::valueno sort_key,
00809 bool ascending = true);
00810
00836 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00837 Xapian::doccount checkatleast = 0,
00838 const RSet * omrset = 0,
00839 const MatchDecider * mdecider = 0) const;
00840 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00841 const RSet * omrset,
00842 const MatchDecider * mdecider = 0) const {
00843 return get_mset(first, maxitems, 0, omrset, mdecider);
00844 }
00845
00846 static const int INCLUDE_QUERY_TERMS = 1;
00847 static const int USE_EXACT_TERMFREQ = 2;
00848 #ifndef _MSC_VER
00849
00850 XAPIAN_DEPRECATED(static const int include_query_terms) = 1;
00852 XAPIAN_DEPRECATED(static const int use_exact_termfreq) = 2;
00853 #else
00854
00855
00856 static const int include_query_terms = 1;
00857 static const int use_exact_termfreq = 2;
00858 #pragma deprecated("Xapian::Enquire::include_query_terms", "Xapian::Enquire::use_exact_termfreq")
00859 #endif
00860
00883 ESet get_eset(Xapian::termcount maxitems,
00884 const RSet & omrset,
00885 int flags = 0,
00886 double k = 1.0,
00887 const Xapian::ExpandDecider * edecider = 0) const;
00888
00902 inline ESet get_eset(Xapian::termcount maxitems, const RSet & omrset,
00903 const Xapian::ExpandDecider * edecider) const {
00904 return get_eset(maxitems, omrset, 0, 1.0, edecider);
00905 }
00906
00935 TermIterator get_matching_terms_begin(Xapian::docid did) const;
00936
00938 TermIterator get_matching_terms_end(Xapian::docid ) const {
00939 return TermIterator(NULL);
00940 }
00941
00964 TermIterator get_matching_terms_begin(const MSetIterator &it) const;
00965
00967 TermIterator get_matching_terms_end(const MSetIterator &) const {
00968 return TermIterator(NULL);
00969 }
00970
00977 void register_match_decider(const std::string &name,
00978 const MatchDecider *mdecider = NULL);
00979
00983 std::string get_description() const;
00984 };
00985
00986 }
00987
00988 class RemoteServer;
00989
00990 namespace Xapian {
00991
00993 class XAPIAN_VISIBILITY_DEFAULT Weight {
00994 friend class Enquire;
00995 friend class ::RemoteServer;
00996 public:
00997 class Internal;
00998 protected:
00999 Weight(const Weight &);
01000 private:
01001 void operator=(Weight &);
01002
01012 virtual Weight * clone() const = 0;
01013
01014 protected:
01015 const Internal * internal;
01016 Xapian::doclength querysize;
01017 Xapian::termcount wqf;
01018 std::string tname;
01019
01020 public:
01021 Weight() { }
01022 virtual ~Weight();
01023
01036 Weight * create(const Internal * internal_, Xapian::doclength querysize_,
01037 Xapian::termcount wqf_, const std::string & tname_) const;
01038
01043 virtual std::string name() const = 0;
01044
01046 virtual std::string serialise() const = 0;
01047
01049 virtual Weight * unserialise(const std::string &s) const = 0;
01050
01058 virtual Xapian::weight get_sumpart(Xapian::termcount wdf,
01059 Xapian::doclength len) const = 0;
01060
01066 virtual Xapian::weight get_maxpart() const = 0;
01067
01076 virtual Xapian::weight get_sumextra(Xapian::doclength len) const = 0;
01077
01081 virtual Xapian::weight get_maxextra() const = 0;
01082
01084 virtual bool get_sumpart_needs_doclength() const;
01085 };
01086
01088 class XAPIAN_VISIBILITY_DEFAULT BoolWeight : public Weight {
01089 public:
01090 BoolWeight * clone() const;
01091 BoolWeight() { }
01092 ~BoolWeight();
01093 std::string name() const;
01094 std::string serialise() const;
01095 BoolWeight * unserialise(const std::string & s) const;
01096 Xapian::weight get_sumpart(Xapian::termcount wdf, Xapian::doclength len) const;
01097 Xapian::weight get_maxpart() const;
01098
01099 Xapian::weight get_sumextra(Xapian::doclength len) const;
01100 Xapian::weight get_maxextra() const;
01101
01102 bool get_sumpart_needs_doclength() const;
01103 };
01104
01117 class XAPIAN_VISIBILITY_DEFAULT BM25Weight : public Weight {
01118 private:
01119 mutable Xapian::weight termweight;
01120 mutable Xapian::doclength lenpart;
01121
01122 double k1, k2, k3, b;
01123 Xapian::doclength min_normlen;
01124
01125 mutable bool weight_calculated;
01126
01127 void calc_termweight() const;
01128
01129 public:
01148 BM25Weight(double k1_, double k2_, double k3_, double b_,
01149 double min_normlen_)
01150 : k1(k1_), k2(k2_), k3(k3_), b(b_), min_normlen(min_normlen_),
01151 weight_calculated(false)
01152 {
01153 if (k1 < 0) k1 = 0;
01154 if (k2 < 0) k2 = 0;
01155 if (k3 < 0) k3 = 0;
01156 if (b < 0) b = 0; else if (b > 1) b = 1;
01157 }
01158 BM25Weight() : k1(1), k2(0), k3(1), b(0.5), min_normlen(0.5),
01159 weight_calculated(false) { }
01160
01161 BM25Weight * clone() const;
01162 ~BM25Weight() { }
01163 std::string name() const;
01164 std::string serialise() const;
01165 BM25Weight * unserialise(const std::string & s) const;
01166 Xapian::weight get_sumpart(Xapian::termcount wdf, Xapian::doclength len) const;
01167 Xapian::weight get_maxpart() const;
01168
01169 Xapian::weight get_sumextra(Xapian::doclength len) const;
01170 Xapian::weight get_maxextra() const;
01171
01172 bool get_sumpart_needs_doclength() const;
01173 };
01174
01192 class XAPIAN_VISIBILITY_DEFAULT TradWeight : public Weight {
01193 private:
01194 mutable Xapian::weight termweight;
01195 mutable Xapian::doclength lenpart;
01196
01197 double param_k;
01198
01199 mutable bool weight_calculated;
01200
01201 void calc_termweight() const;
01202
01203 public:
01211 explicit TradWeight(double k) : param_k(k), weight_calculated(false) {
01212 if (param_k < 0) param_k = 0;
01213 }
01214
01215 TradWeight() : param_k(1.0), weight_calculated(false) { }
01216
01217 TradWeight * clone() const;
01218 ~TradWeight() { }
01219 std::string name() const;
01220 std::string serialise() const;
01221 TradWeight * unserialise(const std::string & s) const;
01222
01223 Xapian::weight get_sumpart(Xapian::termcount wdf, Xapian::doclength len) const;
01224 Xapian::weight get_maxpart() const;
01225
01226 Xapian::weight get_sumextra(Xapian::doclength len) const;
01227 Xapian::weight get_maxextra() const;
01228
01229 bool get_sumpart_needs_doclength() const;
01230 };
01231
01232 }
01233
01234 #endif