00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAPIAN_INCLUDED_REMOTE_DATABASE_H
00023 #define XAPIAN_INCLUDED_REMOTE_DATABASE_H
00024
00025 #include "database.h"
00026 #include "omenquireinternal.h"
00027 #include "omqueryinternal.h"
00028 #include "remoteconnection.h"
00029 #include "valuestats.h"
00030 #include "xapian/weight.h"
00031
00032 namespace Xapian {
00033 class RSet;
00034 }
00035
00036 class NetworkPostList;
00037
00044 class RemoteDatabase : public Xapian::Database::Internal {
00046 void operator=(const RemoteDatabase &);
00047
00049 RemoteDatabase(const RemoteDatabase &);
00050
00052 mutable RemoteConnection link;
00053
00055 mutable Xapian::doccount doccount;
00056
00058 mutable Xapian::docid lastdocid;
00059
00061 mutable Xapian::termcount doclen_lbound;
00062
00064 mutable Xapian::termcount doclen_ubound;
00065
00067 mutable totlen_t total_length;
00068
00070 mutable bool has_positional_info;
00071
00073 mutable string uuid;
00074
00076 string context;
00077
00078 mutable bool cached_stats_valid;
00079
00081 mutable ValueStats mru_valstats;
00082
00087 mutable Xapian::valueno mru_slot;
00088
00089 void update_stats(message_type msg_code = MSG_UPDATE) const;
00090
00091 void apply_stats_update(const char * p, const char * p_end) const;
00092
00093 protected:
00107 RemoteDatabase(int fd, double timeout_, const string & context_,
00108 bool writable);
00109
00111 reply_type get_message(string & message, reply_type required_type = REPLY_MAX) const;
00112
00114 void send_message(message_type type, const string & data) const;
00115
00117 void do_close();
00118
00119 bool get_posting(Xapian::docid &did, Xapian::weight &w, string &value);
00120
00122 double timeout;
00123
00124 public:
00126 RemoteDatabase * as_remotedatabase();
00127
00129 void keep_alive();
00130
00149 void set_query(const Xapian::Query::Internal *query,
00150 Xapian::termcount qlen,
00151 Xapian::doccount collapse_max,
00152 Xapian::valueno collapse_key,
00153 Xapian::Enquire::docid_order order,
00154 Xapian::valueno sort_key,
00155 Xapian::Enquire::Internal::sort_setting sort_by,
00156 bool sort_value_forward,
00157 int percent_cutoff, Xapian::weight weight_cutoff,
00158 const Xapian::Weight *wtscheme,
00159 const Xapian::RSet &omrset,
00160 const vector<Xapian::MatchSpy *> & matchspies);
00161
00166 bool get_remote_stats(bool nowait, Xapian::Weight::Internal &out);
00167
00169 void send_global_stats(Xapian::doccount first,
00170 Xapian::doccount maxitems,
00171 Xapian::doccount check_at_least,
00172 const Xapian::Weight::Internal &stats);
00173
00175 void get_mset(Xapian::MSet &mset,
00176 const vector<Xapian::MatchSpy *> & matchspies);
00177
00179 TermList * open_metadata_keylist(const std::string & prefix) const;
00180
00182 TermList * open_term_list(Xapian::docid did) const;
00183
00185 TermList * open_allterms(const string & prefix) const;
00186
00187 bool has_positions() const;
00188
00189 void reopen();
00190
00191 void close();
00192
00193 LeafPostList * open_post_list(const string & tname) const;
00194
00195 Xapian::doccount read_post_list(const string &term, NetworkPostList & pl) const;
00196
00197 PositionList * open_position_list(Xapian::docid did,
00198 const string & tname) const;
00199
00201 Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const;
00202
00204 Xapian::doccount get_doccount() const;
00205
00207 Xapian::docid get_lastdocid() const;
00208
00209 totlen_t get_total_length() const;
00210
00212 Xapian::doclength get_avlength() const;
00213
00214 Xapian::termcount get_doclength(Xapian::docid did) const;
00215
00217 bool term_exists(const string & tname) const;
00218
00220 Xapian::doccount get_termfreq(const string & tname) const;
00221
00222 Xapian::termcount get_collection_freq(const string & tname) const;
00223
00225 void read_value_stats(Xapian::valueno slot) const;
00226 Xapian::doccount get_value_freq(Xapian::valueno slot) const;
00227 std::string get_value_lower_bound(Xapian::valueno slot) const;
00228 std::string get_value_upper_bound(Xapian::valueno slot) const;
00229
00230 Xapian::termcount get_doclength_lower_bound() const;
00231 Xapian::termcount get_doclength_upper_bound() const;
00232 Xapian::termcount get_wdf_upper_bound(const string & term) const;
00233
00234 void commit();
00235
00236 void cancel();
00237
00238 Xapian::docid add_document(const Xapian::Document & doc);
00239
00240 void delete_document(Xapian::docid did);
00241 void delete_document(const std::string & unique_term);
00242
00243 void replace_document(Xapian::docid did, const Xapian::Document & doc);
00244 Xapian::docid replace_document(const std::string & unique_term,
00245 const Xapian::Document & document);
00246
00247 std::string get_uuid() const;
00248
00249 string get_metadata(const string & key) const;
00250
00251 void set_metadata(const string & key, const string & value);
00252
00253 void add_spelling(const std::string&, Xapian::termcount) const;
00254
00255 void remove_spelling(const std::string&, Xapian::termcount freqdec) const;
00256 };
00257
00258 #endif // XAPIAN_INCLUDED_REMOTE_DATABASE_H