common/omenquireinternal.h

Go to the documentation of this file.
00001 /* omenquireinternal.h: Internals
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2001,2002 Ananova Ltd
00005  * Copyright 2002,2003,2004,2005,2006,2007 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (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
00020  * USA
00021  */
00022 
00023 #ifndef OM_HGUARD_OMENQUIREINTERNAL_H
00024 #define OM_HGUARD_OMENQUIREINTERNAL_H
00025 
00026 #include <xapian/database.h>
00027 #include <xapian/document.h>
00028 #include <xapian/enquire.h>
00029 #include <xapian/sorter.h>
00030 #include <xapian/query.h>
00031 #include <algorithm>
00032 #include <math.h>
00033 #include <map>
00034 #include <set>
00035 
00036 using namespace std;
00037 
00038 class OmExpand;
00039 class RSetI;
00040 class MultiMatch;
00041 
00042 namespace Xapian {
00043 
00044 class ErrorHandler;
00045 class TermIterator;
00046 
00047 namespace Internal {
00048 
00053 class ESetItem {
00054     public:
00055         ESetItem(Xapian::weight wt_, string tname_) : wt(wt_), tname(tname_) { }
00056 
00057         void swap(ESetItem & o) {
00058             std::swap(wt, o.wt);
00059             std::swap(tname, o.tname);
00060         }
00061 
00063         Xapian::weight wt;
00065         string tname;
00066 
00068         string get_description() const;
00069 };
00070 
00075 class MSetItem {
00076     public:
00077         MSetItem(Xapian::weight wt_, Xapian::docid did_)
00078                 : wt(wt_), did(did_), collapse_count(0) {}
00079 
00080         MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_)
00081                 : wt(wt_), did(did_), collapse_key(key_), collapse_count(0) {}
00082 
00083         MSetItem(Xapian::weight wt_, Xapian::docid did_, const string &key_,
00084                  Xapian::doccount collapse_count_)
00085                 : wt(wt_), did(did_), collapse_key(key_),
00086                   collapse_count(collapse_count_) {}
00087 
00088         void swap(MSetItem & o) {
00089             std::swap(wt, o.wt);
00090             std::swap(did, o.did);
00091             std::swap(collapse_key, o.collapse_key);
00092             std::swap(collapse_count, o.collapse_count);
00093             std::swap(sort_key, o.sort_key);
00094         }
00095 
00097         Xapian::weight wt;
00098 
00100         Xapian::docid did;
00101 
00113         string collapse_key;
00114 
00121         Xapian::doccount collapse_count;
00122 
00124         /* FIXME: why not just cache the Xapian::Document here!?! */
00125         string sort_key;
00126 
00128         string get_description() const;
00129 };
00130 
00131 }
00132 
00137 class Enquire::Internal : public Xapian::Internal::RefCntBase {
00138     private:
00140         const Xapian::Database db;
00141 
00143         Query query;
00144 
00146         termcount qlen;
00147 
00149         Internal(const Internal &);
00151         void operator=(const Internal &);
00152 
00153     public:
00154         typedef enum { REL, VAL, VAL_REL, REL_VAL } sort_setting;
00155 
00156         Xapian::valueno collapse_key;
00157 
00158         Xapian::Enquire::docid_order order;
00159 
00160         percent percent_cutoff;
00161 
00162         Xapian::weight weight_cutoff;
00163 
00164         Xapian::valueno sort_key;
00165         sort_setting sort_by;
00166         bool sort_value_forward;
00167 
00168         Sorter * sorter;
00169 
00172         ErrorHandler * errorhandler;
00173 
00174         mutable Weight * weight; // mutable so get_mset can set default
00175 
00176         Internal(const Xapian::Database &databases, ErrorHandler * errorhandler_);
00177         ~Internal();
00178 
00181         void request_doc(const Xapian::Internal::MSetItem &item) const;
00182 
00185         Xapian::Document read_doc(const Xapian::Internal::MSetItem &item) const;
00186 
00187         void set_query(const Query & query_, termcount qlen_);
00188         const Query & get_query();
00189         MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems,
00190                       Xapian::doccount check_at_least,
00191                       const RSet *omrset, const MatchDecider *mdecider,
00192                       const MatchDecider *matchspy) const;
00193         ESet get_eset(Xapian::termcount maxitems, const RSet & omrset, int flags,
00194                       double k, const ExpandDecider *edecider) const;
00195 
00196         TermIterator get_matching_terms(Xapian::docid did) const;
00197         TermIterator get_matching_terms(const Xapian::MSetIterator &it) const;
00198 
00199         void register_match_decider(const string &name,
00200                                     const MatchDecider *mdecider);
00201 
00202         string get_description() const;
00203 };
00204 
00205 class MSet::Internal : public Xapian::Internal::RefCntBase {
00206     public:
00208         double percent_factor;
00209 
00210     private:
00214         mutable set<Xapian::doccount> requested_docs;
00215 
00217         mutable map<Xapian::doccount, Xapian::Document> indexeddocs;
00218 
00220         void read_docs() const;
00221 
00223         Internal(const Internal &);
00225         void operator=(const Internal &);
00226 
00227     public:
00229         Xapian::Internal::RefCntPtr<const Enquire::Internal> enquire;
00230 
00234         struct TermFreqAndWeight {
00235             TermFreqAndWeight() { }
00236             TermFreqAndWeight(Xapian::doccount tf, Xapian::weight wt)
00237                 : termfreq(tf), termweight(wt) { }
00238             Xapian::doccount termfreq;
00239             Xapian::weight termweight;
00240         };
00241 
00247         map<string, TermFreqAndWeight> termfreqandwts;
00248 
00250         vector<Xapian::Internal::MSetItem> items;
00251 
00253         Xapian::doccount firstitem;
00254 
00255         Xapian::doccount matches_lower_bound;
00256 
00257         Xapian::doccount matches_estimated;
00258 
00259         Xapian::doccount matches_upper_bound;
00260 
00261         Xapian::weight max_possible;
00262 
00263         Xapian::weight max_attained;
00264 
00265         Internal()
00266                 : percent_factor(0),
00267                   firstitem(0),
00268                   matches_lower_bound(0),
00269                   matches_estimated(0),
00270                   matches_upper_bound(0),
00271                   max_possible(0),
00272                   max_attained(0) {}
00273 
00274         Internal(Xapian::doccount firstitem_,
00275              Xapian::doccount matches_upper_bound_,
00276              Xapian::doccount matches_lower_bound_,
00277              Xapian::doccount matches_estimated_,
00278              Xapian::weight max_possible_,
00279              Xapian::weight max_attained_,
00280              const vector<Xapian::Internal::MSetItem> &items_,
00281              const map<string, TermFreqAndWeight> &termfreqandwts_,
00282              Xapian::weight percent_factor_)
00283                 : percent_factor(percent_factor_),
00284                   termfreqandwts(termfreqandwts_),
00285                   items(items_),
00286                   firstitem(firstitem_),
00287                   matches_lower_bound(matches_lower_bound_),
00288                   matches_estimated(matches_estimated_),
00289                   matches_upper_bound(matches_upper_bound_),
00290                   max_possible(max_possible_),
00291                   max_attained(max_attained_) {}
00292 
00294         Xapian::Document get_doc_by_index(Xapian::doccount index) const;
00295 
00297         percent convert_to_percent_internal(Xapian::weight wt) const;
00298 
00300         string get_description() const;
00301 
00304         void fetch_items(Xapian::doccount first, Xapian::doccount last) const;
00305 };
00306 
00307 class ESet::Internal : public Xapian::Internal::RefCntBase {
00308     friend class ESet;
00309     friend class ESetIterator;
00310     friend class ::OmExpand;
00311     private:
00313         vector<Xapian::Internal::ESetItem> items;
00314 
00319         Xapian::termcount ebound;
00320 
00321     public:
00322         Internal() : ebound(0) {}
00323 
00325         string get_description() const;
00326 };
00327 
00328 class RSet::Internal : public Xapian::Internal::RefCntBase {
00329     friend class Xapian::RSet;
00330 
00331     private:
00333         set<Xapian::docid> items;
00334 
00335     public:
00336         const set<Xapian::docid> & get_items() const { return items; }
00337 
00339         string get_description() const;
00340 };
00341 
00342 }
00343 
00344 #endif // OM_HGUARD_OMENQUIREINTERNAL_H

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.