include/xapian/postingsource.h

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2007,2008,2009 Olly Betts
00005  * Copyright (C) 2008,2009 Lemur Consulting Ltd
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
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 
00046   protected:
00048     PostingSource() { }
00049 
00050   public:
00051     // Destructor.
00052     virtual ~PostingSource();
00053 
00059     virtual Xapian::doccount get_termfreq_min() const = 0;
00060 
00070     virtual Xapian::doccount get_termfreq_est() const = 0;
00071 
00077     virtual Xapian::doccount get_termfreq_max() const = 0;
00078 
00092     virtual Xapian::weight get_maxweight() const;
00093 
00107     virtual Xapian::weight get_weight() const;
00108 
00118     virtual Xapian::docid get_docid() const = 0;
00119 
00132     virtual void next(Xapian::weight min_wt) = 0;
00133 
00160     virtual void skip_to(Xapian::docid did, Xapian::weight min_wt);
00161 
00193     virtual bool check(Xapian::docid did, Xapian::weight min_wt);
00194 
00200     virtual bool at_end() const = 0;
00201 
00219     virtual PostingSource * clone() const;
00220 
00237     virtual std::string name() const;
00238 
00245     virtual std::string serialise() const;
00246 
00251     virtual PostingSource * unserialise(const std::string &s) const;
00252 
00271     virtual void init(const Database & db) = 0;
00272 
00280     virtual std::string get_description() const;
00281 };
00282 
00289 class XAPIAN_VISIBILITY_DEFAULT ValuePostingSource : public PostingSource {
00290   protected:
00292     Xapian::Database db;
00293 
00295     Xapian::valueno slot;
00296 
00298     Xapian::ValueIterator value_it;
00299 
00301     Xapian::ValueIterator value_end;
00302 
00304     bool started;
00305 
00311     double max_weight;
00312 
00318     Xapian::doccount termfreq_min;
00319 
00325     Xapian::doccount termfreq_est;
00326 
00332     Xapian::doccount termfreq_max;
00333 
00334   public:
00339     ValuePostingSource(Xapian::valueno slot_);
00340 
00341     Xapian::doccount get_termfreq_min() const;
00342     Xapian::doccount get_termfreq_est() const;
00343     Xapian::doccount get_termfreq_max() const;
00344 
00345     Xapian::weight get_maxweight() const;
00346 
00347     void next(Xapian::weight min_wt);
00348     void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00349     bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00350 
00351     bool at_end() const;
00352 
00353     Xapian::docid get_docid() const;
00354 
00355     void init(const Database & db_);
00356 };
00357 
00372 class XAPIAN_VISIBILITY_DEFAULT ValueWeightPostingSource
00373         : public ValuePostingSource {
00374   public:
00379     ValueWeightPostingSource(Xapian::valueno slot_);
00380 
00381     Xapian::weight get_weight() const;
00382     ValueWeightPostingSource * clone() const;
00383     std::string name() const;
00384     std::string serialise() const;
00385     ValueWeightPostingSource * unserialise(const std::string &s) const;
00386     void init(const Database & db_);
00387 
00388     std::string get_description() const;
00389 };
00390 
00399 class XAPIAN_VISIBILITY_DEFAULT ValueMapPostingSource
00400         : public ValuePostingSource {
00402     double default_weight;
00403 
00405     double max_weight_in_map;
00406 
00408     std::map<std::string, double> weight_map;
00409 
00410   public:
00415     ValueMapPostingSource(Xapian::valueno slot_);
00416 
00422     void add_mapping(const std::string &key, double weight);
00423 
00425     void clear_mappings();
00426 
00428     void set_default_weight(double wt);
00429 
00430     Xapian::weight get_weight() const;
00431     ValueMapPostingSource * clone() const;
00432     std::string name() const;
00433     std::string serialise() const;
00434     ValueMapPostingSource * unserialise(const std::string &s) const;
00435     void init(const Database & db_);
00436 
00437     std::string get_description() const;
00438 };
00439 
00445 class XAPIAN_VISIBILITY_DEFAULT FixedWeightPostingSource : public PostingSource {
00447     Xapian::Database db;
00448 
00450     Xapian::doccount termfreq;
00451 
00453     Xapian::PostingIterator it;
00454 
00456     Xapian::PostingIterator end;
00457 
00459     Xapian::weight wt;
00460 
00462     bool started;
00463 
00465     Xapian::docid check_docid;
00466 
00467   public:
00472     FixedWeightPostingSource(Xapian::weight wt_);
00473 
00474     Xapian::doccount get_termfreq_min() const;
00475     Xapian::doccount get_termfreq_est() const;
00476     Xapian::doccount get_termfreq_max() const;
00477 
00478     Xapian::weight get_maxweight() const;
00479     Xapian::weight get_weight() const;
00480 
00481     void next(Xapian::weight min_wt);
00482     void skip_to(Xapian::docid min_docid, Xapian::weight min_wt);
00483     bool check(Xapian::docid min_docid, Xapian::weight min_wt);
00484 
00485     bool at_end() const;
00486 
00487     Xapian::docid get_docid() const;
00488 
00489     FixedWeightPostingSource * clone() const;
00490     std::string name() const;
00491     std::string serialise() const;
00492     FixedWeightPostingSource * unserialise(const std::string &s) const;
00493     void init(const Database & db_);
00494 
00495     std::string get_description() const;
00496 };
00497 
00498 
00499 }
00500 
00501 #endif // XAPIAN_INCLUDED_POSTINGSOURCE_H

Documentation for Xapian (version 1.1.0).
Generated on 22 Apr 2009 by Doxygen 1.5.2.