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
00036 class XAPIAN_VISIBILITY_DEFAULT PostingSource {
00038 void operator=(const PostingSource &);
00039
00041 PostingSource(const PostingSource &);
00042
00044 double max_weight_;
00045
00051 void * matcher_;
00052
00053 protected:
00055 PostingSource() : max_weight_(0), matcher_(NULL) { }
00056
00077 void set_maxweight(Xapian::weight max_weight);
00078
00079 public:
00086 void register_matcher_(void * matcher) { matcher_ = matcher; }
00087
00088
00089 virtual ~PostingSource();
00090
00096 virtual Xapian::doccount get_termfreq_min() const = 0;
00097
00107 virtual Xapian::doccount get_termfreq_est() const = 0;
00108
00114 virtual Xapian::doccount get_termfreq_max() const = 0;
00115
00117 Xapian::weight get_maxweight() const { return max_weight_; }
00118
00132 virtual Xapian::weight get_weight() const;
00133
00143 virtual Xapian::docid get_docid() const = 0;
00144
00157 virtual void next(Xapian::weight min_wt) = 0;
00158
00186 virtual void skip_to(Xapian::docid did, Xapian::weight min_wt);
00187
00223 virtual bool check(Xapian::docid did, Xapian::weight min_wt);
00224
00230 virtual bool at_end() const = 0;
00231
00253 virtual PostingSource * clone() const;
00254
00271 virtual std::string name() const;
00272
00282 virtual std::string serialise() const;
00283
00298 virtual PostingSource * unserialise(const std::string &s) const;
00299
00322 virtual void init(const Database & db) = 0;
00323
00331 virtual std::string get_description() const;
00332 };
00333
00334
00345 class XAPIAN_VISIBILITY_DEFAULT ValuePostingSource : public PostingSource {
00346 protected:
00348 Xapian::Database db;
00349
00351 Xapian::valueno slot;
00352
00354 Xapian::ValueIterator value_it;
00355
00357 bool started;
00358
00364 Xapian::doccount termfreq_min;
00365
00371 Xapian::doccount termfreq_est;
00372
00378 Xapian::doccount termfreq_max;
00379
00380 public:
00385 ValuePostingSource(Xapian::valueno slot_);
00386
00387 Xapian::doccount get_termfreq_min() const;
00388 Xapian::doccount get_termfreq_est() const;
00389 Xapian::doccount get_termfreq_max() const;
00390
00391 void next(Xapian::weight min_wt);
00392 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00393 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00394
00395 bool at_end() const;
00396
00397 Xapian::docid get_docid() const;
00398
00399 void init(const Database & db_);
00400 };
00401
00402
00421 class XAPIAN_VISIBILITY_DEFAULT ValueWeightPostingSource
00422 : public ValuePostingSource {
00423 public:
00428 ValueWeightPostingSource(Xapian::valueno slot_);
00429
00430 Xapian::weight get_weight() const;
00431 ValueWeightPostingSource * clone() const;
00432 std::string name() const;
00433 std::string serialise() const;
00434 ValueWeightPostingSource * unserialise(const std::string &s) const;
00435 void init(const Database & db_);
00436
00437 std::string get_description() const;
00438 };
00439
00440
00460 class XAPIAN_VISIBILITY_DEFAULT DecreasingValueWeightPostingSource
00461 : public Xapian::ValueWeightPostingSource {
00462 protected:
00463 Xapian::docid range_start;
00464 Xapian::docid range_end;
00465 double curr_weight;
00466
00468 bool items_at_end;
00469
00471 void skip_if_in_range(Xapian::weight min_wt);
00472
00473 public:
00474 DecreasingValueWeightPostingSource(Xapian::valueno slot_,
00475 Xapian::docid range_start_ = 0,
00476 Xapian::docid range_end_ = 0);
00477
00478 Xapian::weight get_weight() const;
00479 DecreasingValueWeightPostingSource * clone() const;
00480 std::string name() const;
00481 std::string serialise() const;
00482 DecreasingValueWeightPostingSource * unserialise(const std::string &s) const;
00483 void init(const Xapian::Database & db_);
00484
00485 void next(Xapian::weight min_wt);
00486 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00487 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00488
00489 std::string get_description() const;
00490 };
00491
00492
00501 class XAPIAN_VISIBILITY_DEFAULT ValueMapPostingSource
00502 : public ValuePostingSource {
00504 double default_weight;
00505
00507 double max_weight_in_map;
00508
00510 std::map<std::string, double> weight_map;
00511
00512 public:
00517 ValueMapPostingSource(Xapian::valueno slot_);
00518
00524 void add_mapping(const std::string &key, double wt);
00525
00527 void clear_mappings();
00528
00533 void set_default_weight(double wt);
00534
00535 Xapian::weight get_weight() const;
00536 ValueMapPostingSource * clone() const;
00537 std::string name() const;
00538 std::string serialise() const;
00539 ValueMapPostingSource * unserialise(const std::string &s) const;
00540 void init(const Database & db_);
00541
00542 std::string get_description() const;
00543 };
00544
00545
00551 class XAPIAN_VISIBILITY_DEFAULT FixedWeightPostingSource : public PostingSource {
00553 Xapian::Database db;
00554
00556 Xapian::doccount termfreq;
00557
00559 Xapian::PostingIterator it;
00560
00562 bool started;
00563
00565 Xapian::docid check_docid;
00566
00567 public:
00572 FixedWeightPostingSource(Xapian::weight wt);
00573
00574 Xapian::doccount get_termfreq_min() const;
00575 Xapian::doccount get_termfreq_est() const;
00576 Xapian::doccount get_termfreq_max() const;
00577
00578 Xapian::weight get_weight() const;
00579
00580 void next(Xapian::weight min_wt);
00581 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00582 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00583
00584 bool at_end() const;
00585
00586 Xapian::docid get_docid() const;
00587
00588 FixedWeightPostingSource * clone() const;
00589 std::string name() const;
00590 std::string serialise() const;
00591 FixedWeightPostingSource * unserialise(const std::string &s) const;
00592 void init(const Database & db_);
00593
00594 std::string get_description() const;
00595 };
00596
00597
00598 }
00599
00600 #endif // XAPIAN_INCLUDED_POSTINGSOURCE_H