00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAPIAN_INCLUDED_POSTINGSOURCE_H
00023 #define XAPIAN_INCLUDED_POSTINGSOURCE_H
00024
00025 #include <xapian/database.h>
00026 #include <xapian/types.h>
00027 #include <xapian/visibility.h>
00028
00029 #include <string>
00030 #include <map>
00031
00032 namespace Xapian {
00033
00039 class XAPIAN_VISIBILITY_DEFAULT PostingSource {
00041 void operator=(const PostingSource &);
00042
00044 PostingSource(const PostingSource &);
00045
00047 double max_weight_;
00048
00054 void * matcher_;
00055
00056 protected:
00058 PostingSource() : max_weight_(0), matcher_(NULL) { }
00059
00078 void set_maxweight(Xapian::weight max_weight);
00079
00080 public:
00087 void register_matcher_(void * matcher) { matcher_ = matcher; }
00088
00089
00090 virtual ~PostingSource();
00091
00097 virtual Xapian::doccount get_termfreq_min() const = 0;
00098
00108 virtual Xapian::doccount get_termfreq_est() const = 0;
00109
00115 virtual Xapian::doccount get_termfreq_max() const = 0;
00116
00118 Xapian::weight get_maxweight() const { return max_weight_; }
00119
00133 virtual Xapian::weight get_weight() const;
00134
00144 virtual Xapian::docid get_docid() const = 0;
00145
00158 virtual void next(Xapian::weight min_wt) = 0;
00159
00186 virtual void skip_to(Xapian::docid did, Xapian::weight min_wt);
00187
00219 virtual bool check(Xapian::docid did, Xapian::weight min_wt);
00220
00226 virtual bool at_end() const = 0;
00227
00245 virtual PostingSource * clone() const;
00246
00263 virtual std::string name() const;
00264
00271 virtual std::string serialise() const;
00272
00277 virtual PostingSource * unserialise(const std::string &s) const;
00278
00301 virtual void init(const Database & db) = 0;
00302
00310 virtual std::string get_description() const;
00311 };
00312
00323 class XAPIAN_VISIBILITY_DEFAULT ValuePostingSource : public PostingSource {
00324 protected:
00326 Xapian::Database db;
00327
00329 Xapian::valueno slot;
00330
00332 Xapian::ValueIterator value_it;
00333
00335 bool started;
00336
00342 Xapian::doccount termfreq_min;
00343
00349 Xapian::doccount termfreq_est;
00350
00356 Xapian::doccount termfreq_max;
00357
00358 public:
00363 ValuePostingSource(Xapian::valueno slot_);
00364
00365 Xapian::doccount get_termfreq_min() const;
00366 Xapian::doccount get_termfreq_est() const;
00367 Xapian::doccount get_termfreq_max() const;
00368
00369 void next(Xapian::weight min_wt);
00370 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00371 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00372
00373 bool at_end() const;
00374
00375 Xapian::docid get_docid() const;
00376
00377 void init(const Database & db_);
00378 };
00379
00398 class XAPIAN_VISIBILITY_DEFAULT ValueWeightPostingSource
00399 : public ValuePostingSource {
00400 public:
00405 ValueWeightPostingSource(Xapian::valueno slot_);
00406
00407 Xapian::weight get_weight() const;
00408 ValueWeightPostingSource * clone() const;
00409 std::string name() const;
00410 std::string serialise() const;
00411 ValueWeightPostingSource * unserialise(const std::string &s) const;
00412 void init(const Database & db_);
00413
00414 std::string get_description() const;
00415 };
00416
00425 class XAPIAN_VISIBILITY_DEFAULT ValueMapPostingSource
00426 : public ValuePostingSource {
00428 double default_weight;
00429
00431 double max_weight_in_map;
00432
00434 std::map<std::string, double> weight_map;
00435
00436 public:
00441 ValueMapPostingSource(Xapian::valueno slot_);
00442
00448 void add_mapping(const std::string &key, double weight);
00449
00451 void clear_mappings();
00452
00454 void set_default_weight(double wt);
00455
00456 Xapian::weight get_weight() const;
00457 ValueMapPostingSource * clone() const;
00458 std::string name() const;
00459 std::string serialise() const;
00460 ValueMapPostingSource * unserialise(const std::string &s) const;
00461 void init(const Database & db_);
00462
00463 std::string get_description() const;
00464 };
00465
00471 class XAPIAN_VISIBILITY_DEFAULT FixedWeightPostingSource : public PostingSource {
00473 Xapian::Database db;
00474
00476 Xapian::doccount termfreq;
00477
00479 Xapian::PostingIterator it;
00480
00482 bool started;
00483
00485 Xapian::docid check_docid;
00486
00487 public:
00492 FixedWeightPostingSource(Xapian::weight wt);
00493
00494 Xapian::doccount get_termfreq_min() const;
00495 Xapian::doccount get_termfreq_est() const;
00496 Xapian::doccount get_termfreq_max() const;
00497
00498 Xapian::weight get_weight() const;
00499
00500 void next(Xapian::weight min_wt);
00501 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00502 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00503
00504 bool at_end() const;
00505
00506 Xapian::docid get_docid() const;
00507
00508 FixedWeightPostingSource * clone() const;
00509 std::string name() const;
00510 std::string serialise() const;
00511 FixedWeightPostingSource * unserialise(const std::string &s) const;
00512 void init(const Database & db_);
00513
00514 std::string get_description() const;
00515 };
00516
00517
00518 }
00519
00520 #endif // XAPIAN_INCLUDED_POSTINGSOURCE_H