00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef XAPIAN_INCLUDED_ENQUIRE_H
00027 #define XAPIAN_INCLUDED_ENQUIRE_H
00028
00029 #include <string>
00030
00031 #include <xapian/base.h>
00032 #include <xapian/deprecated.h>
00033 #include <xapian/keymaker.h>
00034 #include <xapian/types.h>
00035 #include <xapian/termiterator.h>
00036 #include <xapian/visibility.h>
00037
00038 namespace Xapian {
00039
00040 class Database;
00041 class Document;
00042 class ErrorHandler;
00043 class ExpandDecider;
00044 class MatchSpy;
00045 class MSetIterator;
00046 class Query;
00047 class Weight;
00048
00052 class XAPIAN_VISIBILITY_DEFAULT MSet {
00053 public:
00054 class Internal;
00056 Xapian::Internal::RefCntPtr<Internal> internal;
00057
00059 explicit MSet(MSet::Internal * internal_);
00060
00062 MSet();
00063
00065 ~MSet();
00066
00068 MSet(const MSet & other);
00069
00071 void operator=(const MSet &other);
00072
00088 void fetch(const MSetIterator &begin, const MSetIterator &end) const;
00089
00092 void fetch(const MSetIterator &item) const;
00093
00096 void fetch() const;
00097
00104 Xapian::percent convert_to_percent(Xapian::weight wt) const;
00105
00107 Xapian::percent convert_to_percent(const MSetIterator &it) const;
00108
00117 Xapian::doccount get_termfreq(const std::string &tname) const;
00118
00126 Xapian::weight get_termweight(const std::string &tname) const;
00127
00135 Xapian::doccount get_firstitem() const;
00136
00146 Xapian::doccount get_matches_lower_bound() const;
00147
00160 Xapian::doccount get_matches_estimated() const;
00161
00171 Xapian::doccount get_matches_upper_bound() const;
00172
00176 Xapian::doccount get_uncollapsed_matches_lower_bound() const;
00177
00181 Xapian::doccount get_uncollapsed_matches_estimated() const;
00182
00186 Xapian::doccount get_uncollapsed_matches_upper_bound() const;
00187
00194 Xapian::weight get_max_possible() const;
00195
00209 Xapian::weight get_max_attained() const;
00210
00212 Xapian::doccount size() const;
00213
00215 Xapian::doccount max_size() const { return size(); }
00216
00218 bool empty() const;
00219
00221 void swap(MSet & other);
00222
00224 MSetIterator begin() const;
00225
00227 MSetIterator end() const;
00228
00230 MSetIterator back() const;
00231
00243 MSetIterator operator[](Xapian::doccount i) const;
00244
00246
00247 typedef MSetIterator value_type;
00248 typedef MSetIterator iterator;
00249 typedef MSetIterator const_iterator;
00250 typedef MSetIterator & reference;
00251 typedef MSetIterator & const_reference;
00252 typedef MSetIterator * pointer;
00253 typedef Xapian::doccount_diff difference_type;
00254 typedef Xapian::doccount size_type;
00256
00258 std::string get_description() const;
00259 };
00260
00264 class XAPIAN_VISIBILITY_DEFAULT MSetIterator {
00265 private:
00266 friend class MSet;
00267 friend bool operator==(const MSetIterator &a, const MSetIterator &b);
00268 friend bool operator!=(const MSetIterator &a, const MSetIterator &b);
00269
00270 MSetIterator(Xapian::doccount index_, const MSet & mset_)
00271 : index(index_), mset(mset_) { }
00272
00273 Xapian::doccount index;
00274 MSet mset;
00275
00276 public:
00280 MSetIterator() : index(0), mset() { }
00281
00283 MSetIterator(const MSetIterator &other) {
00284 index = other.index;
00285 mset = other.mset;
00286 }
00287
00289 void operator=(const MSetIterator &other) {
00290 index = other.index;
00291 mset = other.mset;
00292 }
00293
00295 MSetIterator & operator++() {
00296 ++index;
00297 return *this;
00298 }
00299
00301 MSetIterator operator++(int) {
00302 MSetIterator tmp = *this;
00303 ++index;
00304 return tmp;
00305 }
00306
00308 MSetIterator & operator--() {
00309 --index;
00310 return *this;
00311 }
00312
00314 MSetIterator operator--(int) {
00315 MSetIterator tmp = *this;
00316 --index;
00317 return tmp;
00318 }
00319
00321 Xapian::docid operator*() const;
00322
00339 Xapian::Document get_document() const;
00340
00347 Xapian::doccount get_rank() const {
00348 return mset.get_firstitem() + index;
00349 }
00350
00352 Xapian::weight get_weight() const;
00353
00356 std::string get_collapse_key() const;
00357
00374 Xapian::doccount get_collapse_count() const;
00375
00391 Xapian::percent get_percent() const;
00392
00394 std::string get_description() const;
00395
00397
00398 typedef std::bidirectional_iterator_tag iterator_category;
00399 typedef Xapian::docid value_type;
00400 typedef Xapian::doccount_diff difference_type;
00401 typedef Xapian::docid * pointer;
00402 typedef Xapian::docid & reference;
00404 };
00405
00407 inline bool operator==(const MSetIterator &a, const MSetIterator &b)
00408 {
00409 return (a.index == b.index);
00410 }
00411
00413 inline bool operator!=(const MSetIterator &a, const MSetIterator &b)
00414 {
00415 return (a.index != b.index);
00416 }
00417
00418 class ESetIterator;
00419
00424 class XAPIAN_VISIBILITY_DEFAULT ESet {
00425 public:
00426 class Internal;
00428 Xapian::Internal::RefCntPtr<Internal> internal;
00429
00431 ESet();
00432
00434 ~ESet();
00435
00437 ESet(const ESet & other);
00438
00440 void operator=(const ESet &other);
00441
00446 Xapian::termcount get_ebound() const;
00447
00449 Xapian::termcount size() const;
00450
00452 Xapian::termcount max_size() const { return size(); }
00453
00455 bool empty() const;
00456
00458 void swap(ESet & other);
00459
00461 ESetIterator begin() const;
00462
00464 ESetIterator end() const;
00465
00467 ESetIterator back() const;
00468
00473 ESetIterator operator[](Xapian::termcount i) const;
00474
00476 std::string get_description() const;
00477 };
00478
00480 class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
00481 private:
00482 friend class ESet;
00483 friend bool operator==(const ESetIterator &a, const ESetIterator &b);
00484 friend bool operator!=(const ESetIterator &a, const ESetIterator &b);
00485
00486 ESetIterator(Xapian::termcount index_, const ESet & eset_)
00487 : index(index_), eset(eset_) { }
00488
00489 Xapian::termcount index;
00490 ESet eset;
00491
00492 public:
00496 ESetIterator() : index(0), eset() { }
00497
00499 ESetIterator(const ESetIterator &other) {
00500 index = other.index;
00501 eset = other.eset;
00502 }
00503
00505 void operator=(const ESetIterator &other) {
00506 index = other.index;
00507 eset = other.eset;
00508 }
00509
00511 ESetIterator & operator++() {
00512 ++index;
00513 return *this;
00514 }
00515
00517 ESetIterator operator++(int) {
00518 ESetIterator tmp = *this;
00519 ++index;
00520 return tmp;
00521 }
00522
00524 ESetIterator & operator--() {
00525 --index;
00526 return *this;
00527 }
00528
00530 ESetIterator operator--(int) {
00531 ESetIterator tmp = *this;
00532 --index;
00533 return tmp;
00534 }
00535
00537 const std::string & operator *() const;
00538
00540 Xapian::weight get_weight() const;
00541
00543 std::string get_description() const;
00544
00546
00547 typedef std::bidirectional_iterator_tag iterator_category;
00548 typedef std::string value_type;
00549 typedef Xapian::termcount_diff difference_type;
00550 typedef std::string * pointer;
00551 typedef std::string & reference;
00553 };
00554
00556 inline bool operator==(const ESetIterator &a, const ESetIterator &b)
00557 {
00558 return (a.index == b.index);
00559 }
00560
00562 inline bool operator!=(const ESetIterator &a, const ESetIterator &b)
00563 {
00564 return (a.index != b.index);
00565 }
00566
00571 class XAPIAN_VISIBILITY_DEFAULT RSet {
00572 public:
00574 class Internal;
00575
00577 Xapian::Internal::RefCntPtr<Internal> internal;
00578
00580 RSet(const RSet &rset);
00581
00583 void operator=(const RSet &rset);
00584
00586 RSet();
00587
00589 ~RSet();
00590
00592 Xapian::doccount size() const;
00593
00595 bool empty() const;
00596
00598 void add_document(Xapian::docid did);
00599
00601 void add_document(const Xapian::MSetIterator & i) { add_document(*i); }
00602
00604 void remove_document(Xapian::docid did);
00605
00607 void remove_document(const Xapian::MSetIterator & i) { remove_document(*i); }
00608
00610 bool contains(Xapian::docid did) const;
00611
00613 bool contains(const Xapian::MSetIterator & i) const { return contains(*i); }
00614
00616 std::string get_description() const;
00617 };
00618
00621 class XAPIAN_VISIBILITY_DEFAULT MatchDecider {
00622 public:
00630 virtual bool operator()(const Xapian::Document &doc) const = 0;
00631
00633 virtual ~MatchDecider();
00634 };
00635
00646 class XAPIAN_VISIBILITY_DEFAULT Enquire {
00647 public:
00649 Enquire(const Enquire & other);
00650
00652 void operator=(const Enquire & other);
00653
00654 class Internal;
00656 Xapian::Internal::RefCntPtr<Internal> internal;
00657
00682 explicit Enquire(const Database &database, ErrorHandler * errorhandler_ = 0);
00683
00686 ~Enquire();
00687
00694 void set_query(const Xapian::Query & query, Xapian::termcount qlen = 0);
00695
00702 const Xapian::Query & get_query() const;
00703
00724 void add_matchspy(MatchSpy * spy);
00725
00728 void clear_matchspies();
00729
00736 void set_weighting_scheme(const Weight &weight_);
00737
00769 void set_collapse_key(Xapian::valueno collapse_key,
00770 Xapian::doccount collapse_max = 1);
00771
00772 typedef enum {
00773 ASCENDING = 1,
00774 DESCENDING = 0,
00775 DONT_CARE = 2
00776 } docid_order;
00777
00803 void set_docid_order(docid_order order);
00804
00823 void set_cutoff(Xapian::percent percent_cutoff, Xapian::weight weight_cutoff = 0);
00824
00829 void set_sort_by_relevance();
00830
00844 void set_sort_by_value(Xapian::valueno sort_key, bool reverse);
00845
00846 XAPIAN_DEPRECATED(void set_sort_by_value(Xapian::valueno sort_key));
00847
00854 void set_sort_by_key(Xapian::KeyMaker * sorter, bool reverse);
00855
00856 XAPIAN_DEPRECATED(void set_sort_by_key(Xapian::KeyMaker * sorter));
00857
00872 void set_sort_by_value_then_relevance(Xapian::valueno sort_key,
00873 bool reverse);
00874
00875 XAPIAN_DEPRECATED(void set_sort_by_value_then_relevance(Xapian::valueno sort_key));
00876
00884 void set_sort_by_key_then_relevance(Xapian::KeyMaker * sorter,
00885 bool reverse);
00886
00887 XAPIAN_DEPRECATED(void set_sort_by_key_then_relevance(Xapian::KeyMaker * sorter));
00888
00909 void set_sort_by_relevance_then_value(Xapian::valueno sort_key,
00910 bool reverse);
00911
00912 XAPIAN_DEPRECATED(void set_sort_by_relevance_then_value(Xapian::valueno sort_key));
00913
00929 void set_sort_by_relevance_then_key(Xapian::KeyMaker * sorter,
00930 bool reverse);
00931
00932 XAPIAN_DEPRECATED(void set_sort_by_relevance_then_key(Xapian::KeyMaker * sorter));
00933
00984 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00985 Xapian::doccount checkatleast = 0,
00986 const RSet * omrset = 0,
00987 const MatchDecider * mdecider = 0) const;
00988 XAPIAN_DEPRECATED(
00989 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00990 Xapian::doccount checkatleast,
00991 const RSet * omrset,
00992 const MatchDecider * mdecider,
00993 const MatchDecider * matchspy) const);
00994 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00995 const RSet * omrset,
00996 const MatchDecider * mdecider = 0) const {
00997 return get_mset(first, maxitems, 0, omrset, mdecider);
00998 }
01001 static const int INCLUDE_QUERY_TERMS = 1;
01002 static const int USE_EXACT_TERMFREQ = 2;
01003
01026 ESet get_eset(Xapian::termcount maxitems,
01027 const RSet & omrset,
01028 int flags = 0,
01029 double k = 1.0,
01030 const Xapian::ExpandDecider * edecider = 0) const;
01031
01045 inline ESet get_eset(Xapian::termcount maxitems, const RSet & omrset,
01046 const Xapian::ExpandDecider * edecider) const {
01047 return get_eset(maxitems, omrset, 0, 1.0, edecider);
01048 }
01049
01074 ESet get_eset(Xapian::termcount maxitems,
01075 const RSet & omrset,
01076 int flags,
01077 double k,
01078 const Xapian::ExpandDecider * edecider,
01079 Xapian::weight min_wt) const;
01080
01109 TermIterator get_matching_terms_begin(Xapian::docid did) const;
01110
01112 TermIterator get_matching_terms_end(Xapian::docid ) const {
01113 return TermIterator();
01114 }
01115
01138 TermIterator get_matching_terms_begin(const MSetIterator &it) const;
01139
01141 TermIterator get_matching_terms_end(const MSetIterator &) const {
01142 return TermIterator();
01143 }
01144
01146 std::string get_description() const;
01147 };
01148
01149
01150
01151 inline void
01152 Enquire::set_sort_by_value(Xapian::valueno sort_key)
01153 {
01154 return set_sort_by_value(sort_key, true);
01155 }
01156
01157 inline void
01158 Enquire::set_sort_by_key(Xapian::KeyMaker * sorter)
01159 {
01160 return set_sort_by_key(sorter, true);
01161 }
01162
01163 inline void
01164 Enquire::set_sort_by_value_then_relevance(Xapian::valueno sort_key)
01165 {
01166 return set_sort_by_value_then_relevance(sort_key, true);
01167 }
01168
01169 inline void
01170 Enquire::set_sort_by_key_then_relevance(Xapian::KeyMaker * sorter)
01171 {
01172 return set_sort_by_key_then_relevance(sorter, true);
01173 }
01174
01175 inline void
01176 Enquire::set_sort_by_relevance_then_value(Xapian::valueno sort_key)
01177 {
01178 return set_sort_by_relevance_then_value(sort_key, true);
01179 }
01180
01181 inline void
01182 Enquire::set_sort_by_relevance_then_key(Xapian::KeyMaker * sorter)
01183 {
01184 return set_sort_by_relevance_then_key(sorter, true);
01185 }
01186
01187 }
01188
01189 #endif