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
00280 virtual PostingSource * unserialise(const std::string &s) const;
00281
00304 virtual void init(const Database & db) = 0;
00305
00313 virtual std::string get_description() const;
00314 };
00315
00326 class XAPIAN_VISIBILITY_DEFAULT ValuePostingSource : public PostingSource {
00327 protected:
00329 Xapian::Database db;
00330
00332 Xapian::valueno slot;
00333
00335 Xapian::ValueIterator value_it;
00336
00338 bool started;
00339
00345 Xapian::doccount termfreq_min;
00346
00352 Xapian::doccount termfreq_est;
00353
00359 Xapian::doccount termfreq_max;
00360
00361 public:
00366 ValuePostingSource(Xapian::valueno slot_);
00367
00368 Xapian::doccount get_termfreq_min() const;
00369 Xapian::doccount get_termfreq_est() const;
00370 Xapian::doccount get_termfreq_max() const;
00371
00372 void next(Xapian::weight min_wt);
00373 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00374 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00375
00376 bool at_end() const;
00377
00378 Xapian::docid get_docid() const;
00379
00380 void init(const Database & db_);
00381 };
00382
00401 class XAPIAN_VISIBILITY_DEFAULT ValueWeightPostingSource
00402 : public ValuePostingSource {
00403 public:
00408 ValueWeightPostingSource(Xapian::valueno slot_);
00409
00410 Xapian::weight get_weight() const;
00411 ValueWeightPostingSource * clone() const;
00412 std::string name() const;
00413 std::string serialise() const;
00414 ValueWeightPostingSource * unserialise(const std::string &s) const;
00415 void init(const Database & db_);
00416
00417 std::string get_description() const;
00418 };
00419
00428 class XAPIAN_VISIBILITY_DEFAULT ValueMapPostingSource
00429 : public ValuePostingSource {
00431 double default_weight;
00432
00434 double max_weight_in_map;
00435
00437 std::map<std::string, double> weight_map;
00438
00439 public:
00444 ValueMapPostingSource(Xapian::valueno slot_);
00445
00451 void add_mapping(const std::string &key, double weight);
00452
00454 void clear_mappings();
00455
00457 void set_default_weight(double wt);
00458
00459 Xapian::weight get_weight() const;
00460 ValueMapPostingSource * clone() const;
00461 std::string name() const;
00462 std::string serialise() const;
00463 ValueMapPostingSource * unserialise(const std::string &s) const;
00464 void init(const Database & db_);
00465
00466 std::string get_description() const;
00467 };
00468
00474 class XAPIAN_VISIBILITY_DEFAULT FixedWeightPostingSource : public PostingSource {
00476 Xapian::Database db;
00477
00479 Xapian::doccount termfreq;
00480
00482 Xapian::PostingIterator it;
00483
00485 bool started;
00486
00488 Xapian::docid check_docid;
00489
00490 public:
00495 FixedWeightPostingSource(Xapian::weight wt);
00496
00497 Xapian::doccount get_termfreq_min() const;
00498 Xapian::doccount get_termfreq_est() const;
00499 Xapian::doccount get_termfreq_max() const;
00500
00501 Xapian::weight get_weight() const;
00502
00503 void next(Xapian::weight min_wt);
00504 void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00505 bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00506
00507 bool at_end() const;
00508
00509 Xapian::docid get_docid() const;
00510
00511 FixedWeightPostingSource * clone() const;
00512 std::string name() const;
00513 std::string serialise() const;
00514 FixedWeightPostingSource * unserialise(const std::string &s) const;
00515 void init(const Database & db_);
00516
00517 std::string get_description() const;
00518 };
00519
00520
00521 }
00522
00523 #endif // XAPIAN_INCLUDED_POSTINGSOURCE_H