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/sorter.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
00112 Xapian::doccount get_termfreq(const std::string &tname) const;
00113
00121 Xapian::weight get_termweight(const std::string &tname) const;
00122
00130 Xapian::doccount get_firstitem() const;
00131
00141 Xapian::doccount get_matches_lower_bound() const;
00142
00155 Xapian::doccount get_matches_estimated() const;
00156
00166 Xapian::doccount get_matches_upper_bound() const;
00167
00171 Xapian::doccount get_uncollapsed_matches_lower_bound() const;
00172
00176 Xapian::doccount get_uncollapsed_matches_estimated() const;
00177
00181 Xapian::doccount get_uncollapsed_matches_upper_bound() const;
00182
00189 Xapian::weight get_max_possible() const;
00190
00204 Xapian::weight get_max_attained() const;
00205
00207 Xapian::doccount size() const;
00208
00210 Xapian::doccount max_size() const { return size(); }
00211
00213 bool empty() const;
00214
00216 void swap(MSet & other);
00217
00219 MSetIterator begin() const;
00220
00222 MSetIterator end() const;
00223
00225 MSetIterator back() const;
00226
00236 MSetIterator operator[](Xapian::doccount i) const;
00237
00239
00240 typedef MSetIterator value_type;
00241 typedef MSetIterator iterator;
00242 typedef MSetIterator const_iterator;
00243 typedef MSetIterator & reference;
00244 typedef MSetIterator & const_reference;
00245 typedef MSetIterator * pointer;
00246 typedef Xapian::doccount_diff difference_type;
00247 typedef Xapian::doccount size_type;
00249
00251 std::string get_description() const;
00252 };
00253
00257 class XAPIAN_VISIBILITY_DEFAULT MSetIterator {
00258 private:
00259 friend class MSet;
00260 friend bool operator==(const MSetIterator &a, const MSetIterator &b);
00261 friend bool operator!=(const MSetIterator &a, const MSetIterator &b);
00262
00263 MSetIterator(Xapian::doccount index_, const MSet & mset_)
00264 : index(index_), mset(mset_) { }
00265
00266 Xapian::doccount index;
00267 MSet mset;
00268
00269 public:
00273 MSetIterator() : index(0), mset() { }
00274
00276 MSetIterator(const MSetIterator &other) {
00277 index = other.index;
00278 mset = other.mset;
00279 }
00280
00282 void operator=(const MSetIterator &other) {
00283 index = other.index;
00284 mset = other.mset;
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 MSetIterator & operator--() {
00302 --index;
00303 return *this;
00304 }
00305
00307 MSetIterator operator--(int) {
00308 MSetIterator tmp = *this;
00309 --index;
00310 return tmp;
00311 }
00312
00314 Xapian::docid operator*() const;
00315
00332 Xapian::Document get_document() const;
00333
00340 Xapian::doccount get_rank() const {
00341 return mset.get_firstitem() + index;
00342 }
00343
00345 Xapian::weight get_weight() const;
00346
00349 std::string get_collapse_key() const;
00350
00367 Xapian::doccount get_collapse_count() const;
00368
00384 Xapian::percent get_percent() const;
00385
00387 std::string get_description() const;
00388
00390
00391 typedef std::bidirectional_iterator_tag iterator_category;
00392 typedef Xapian::docid value_type;
00393 typedef Xapian::doccount_diff difference_type;
00394 typedef Xapian::docid * pointer;
00395 typedef Xapian::docid & reference;
00397 };
00398
00399 inline bool operator==(const MSetIterator &a, const MSetIterator &b)
00400 {
00401 return (a.index == b.index);
00402 }
00403
00404 inline bool operator!=(const MSetIterator &a, const MSetIterator &b)
00405 {
00406 return (a.index != b.index);
00407 }
00408
00409 class ESetIterator;
00410
00415 class XAPIAN_VISIBILITY_DEFAULT ESet {
00416 public:
00417 class Internal;
00419 Xapian::Internal::RefCntPtr<Internal> internal;
00420
00422 ESet();
00423
00425 ~ESet();
00426
00428 ESet(const ESet & other);
00429
00431 void operator=(const ESet &other);
00432
00437 Xapian::termcount get_ebound() const;
00438
00440 Xapian::termcount size() const;
00441
00443 Xapian::termcount max_size() const { return size(); }
00444
00446 bool empty() const;
00447
00449 void swap(ESet & other);
00450
00452 ESetIterator begin() const;
00453
00455 ESetIterator end() const;
00456
00458 ESetIterator back() const;
00459
00461 ESetIterator operator[](Xapian::termcount i) const;
00462
00464 std::string get_description() const;
00465 };
00466
00468 class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
00469 private:
00470 friend class ESet;
00471 friend bool operator==(const ESetIterator &a, const ESetIterator &b);
00472 friend bool operator!=(const ESetIterator &a, const ESetIterator &b);
00473
00474 ESetIterator(Xapian::termcount index_, const ESet & eset_)
00475 : index(index_), eset(eset_) { }
00476
00477 Xapian::termcount index;
00478 ESet eset;
00479
00480 public:
00484 ESetIterator() : index(0), eset() { }
00485
00487 ESetIterator(const ESetIterator &other) {
00488 index = other.index;
00489 eset = other.eset;
00490 }
00491
00493 void operator=(const ESetIterator &other) {
00494 index = other.index;
00495 eset = other.eset;
00496 }
00497
00499 ESetIterator & operator++() {
00500 ++index;
00501 return *this;
00502 }
00503
00505 ESetIterator operator++(int) {
00506 ESetIterator tmp = *this;
00507 ++index;
00508 return tmp;
00509 }
00510
00512 ESetIterator & operator--() {
00513 --index;
00514 return *this;
00515 }
00516
00518 ESetIterator operator--(int) {
00519 ESetIterator tmp = *this;
00520 --index;
00521 return tmp;
00522 }
00523
00525 const std::string & operator *() const;
00526
00528 Xapian::weight get_weight() const;
00529
00531 std::string get_description() const;
00532
00534
00535 typedef std::bidirectional_iterator_tag iterator_category;
00536 typedef std::string value_type;
00537 typedef Xapian::termcount_diff difference_type;
00538 typedef std::string * pointer;
00539 typedef std::string & reference;
00541 };
00542
00543 inline bool operator==(const ESetIterator &a, const ESetIterator &b)
00544 {
00545 return (a.index == b.index);
00546 }
00547
00548 inline bool operator!=(const ESetIterator &a, const ESetIterator &b)
00549 {
00550 return (a.index != b.index);
00551 }
00552
00557 class XAPIAN_VISIBILITY_DEFAULT RSet {
00558 public:
00560 class Internal;
00561
00563 Xapian::Internal::RefCntPtr<Internal> internal;
00564
00566 RSet(const RSet &rset);
00567
00569 void operator=(const RSet &rset);
00570
00572 RSet();
00573
00575 ~RSet();
00576
00578 Xapian::doccount size() const;
00579
00581 bool empty() const;
00582
00584 void add_document(Xapian::docid did);
00585
00587 void add_document(const Xapian::MSetIterator & i) { add_document(*i); }
00588
00590 void remove_document(Xapian::docid did);
00591
00593 void remove_document(const Xapian::MSetIterator & i) { remove_document(*i); }
00594
00596 bool contains(Xapian::docid did) const;
00597
00599 bool contains(const Xapian::MSetIterator & i) const { return contains(*i); }
00600
00602 std::string get_description() const;
00603 };
00604
00607 class XAPIAN_VISIBILITY_DEFAULT MatchDecider {
00608 public:
00614 virtual bool operator()(const Xapian::Document &doc) const = 0;
00615
00617 virtual ~MatchDecider();
00618 };
00619
00630 class XAPIAN_VISIBILITY_DEFAULT Enquire {
00631 public:
00633 Enquire(const Enquire & other);
00634
00636 void operator=(const Enquire & other);
00637
00638 class Internal;
00640 Xapian::Internal::RefCntPtr<Internal> internal;
00641
00666 explicit Enquire(const Database &database, ErrorHandler * errorhandler_ = 0);
00667
00670 ~Enquire();
00671
00678 void set_query(const Xapian::Query & query, Xapian::termcount qlen = 0);
00679
00686 const Xapian::Query & get_query() const;
00687
00694 void set_weighting_scheme(const Weight &weight_);
00695
00727 void set_collapse_key(Xapian::valueno collapse_key,
00728 Xapian::doccount collapse_max = 1);
00729
00730 typedef enum {
00731 ASCENDING = 1,
00732 DESCENDING = 0,
00733 DONT_CARE = 2
00734 } docid_order;
00735
00759 void set_docid_order(docid_order order);
00760
00779 void set_cutoff(Xapian::percent percent_cutoff, Xapian::weight weight_cutoff = 0);
00780
00785 void set_sort_by_relevance();
00786
00797 void set_sort_by_value(Xapian::valueno sort_key, bool reverse);
00798
00799 XAPIAN_DEPRECATED(void set_sort_by_value(Xapian::valueno sort_key));
00800
00807 void set_sort_by_key(Xapian::Sorter * sorter, bool reverse);
00808
00809 XAPIAN_DEPRECATED(void set_sort_by_key(Xapian::Sorter * sorter));
00810
00822 void set_sort_by_value_then_relevance(Xapian::valueno sort_key,
00823 bool reverse);
00824
00825 XAPIAN_DEPRECATED(void set_sort_by_value_then_relevance(Xapian::valueno sort_key));
00826
00834 void set_sort_by_key_then_relevance(Xapian::Sorter * sorter,
00835 bool reverse);
00836
00837 XAPIAN_DEPRECATED(void set_sort_by_key_then_relevance(Xapian::Sorter * sorter));
00838
00856 void set_sort_by_relevance_then_value(Xapian::valueno sort_key,
00857 bool reverse);
00858
00859 XAPIAN_DEPRECATED(void set_sort_by_relevance_then_value(Xapian::valueno sort_key));
00860
00875 void set_sort_by_relevance_then_key(Xapian::Sorter * sorter,
00876 bool reverse);
00877
00878 XAPIAN_DEPRECATED(void set_sort_by_relevance_then_key(Xapian::Sorter * sorter));
00879
00924 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00925 Xapian::doccount checkatleast = 0,
00926 const RSet * omrset = 0,
00927 const MatchDecider * mdecider = 0,
00928 const MatchDecider * matchspy = 0) const;
00929 MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00930 const RSet * omrset,
00931 const MatchDecider * mdecider = 0) const {
00932 return get_mset(first, maxitems, 0, omrset, mdecider);
00933 }
00934
00935 static const int INCLUDE_QUERY_TERMS = 1;
00936 static const int USE_EXACT_TERMFREQ = 2;
00937
00960 ESet get_eset(Xapian::termcount maxitems,
00961 const RSet & omrset,
00962 int flags = 0,
00963 double k = 1.0,
00964 const Xapian::ExpandDecider * edecider = 0) const;
00965
00979 inline ESet get_eset(Xapian::termcount maxitems, const RSet & omrset,
00980 const Xapian::ExpandDecider * edecider) const {
00981 return get_eset(maxitems, omrset, 0, 1.0, edecider);
00982 }
00983
01012 TermIterator get_matching_terms_begin(Xapian::docid did) const;
01013
01015 TermIterator get_matching_terms_end(Xapian::docid ) const {
01016 return TermIterator(NULL);
01017 }
01018
01041 TermIterator get_matching_terms_begin(const MSetIterator &it) const;
01042
01044 TermIterator get_matching_terms_end(const MSetIterator &) const {
01045 return TermIterator(NULL);
01046 }
01047
01049 std::string get_description() const;
01050 };
01051
01052
01053
01054 inline void
01055 Enquire::set_sort_by_value(Xapian::valueno sort_key)
01056 {
01057 return set_sort_by_value(sort_key, true);
01058 }
01059
01060 inline void
01061 Enquire::set_sort_by_key(Xapian::Sorter * sorter)
01062 {
01063 return set_sort_by_key(sorter, true);
01064 }
01065
01066 inline void
01067 Enquire::set_sort_by_value_then_relevance(Xapian::valueno sort_key)
01068 {
01069 return set_sort_by_value_then_relevance(sort_key, true);
01070 }
01071
01072 inline void
01073 Enquire::set_sort_by_key_then_relevance(Xapian::Sorter * sorter)
01074 {
01075 return set_sort_by_key_then_relevance(sorter, true);
01076 }
01077
01078 inline void
01079 Enquire::set_sort_by_relevance_then_value(Xapian::valueno sort_key)
01080 {
01081 return set_sort_by_relevance_then_value(sort_key, true);
01082 }
01083
01084 inline void
01085 Enquire::set_sort_by_relevance_then_key(Xapian::Sorter * sorter)
01086 {
01087 return set_sort_by_relevance_then_key(sorter, true);
01088 }
01089
01090 }
01091
01092 #endif