xapian-core  1.4.30
remote-database.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006,2007,2009,2010,2011,2014,2015,2019,2020 Olly Betts
5  * Copyright (C) 2007,2009,2010 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_REMOTE_DATABASE_H
23 #define XAPIAN_INCLUDED_REMOTE_DATABASE_H
24 
25 #include "backends/backends.h"
26 #include "backends/database.h"
27 #include "api/omenquireinternal.h"
28 #include "api/queryinternal.h"
29 #include "net/remoteconnection.h"
30 #include "backends/valuestats.h"
31 #include "xapian/weight.h"
32 
33 namespace Xapian {
34  class RSet;
35 }
36 
37 class NetworkPostList;
38 
47  void operator=(const RemoteDatabase &);
48 
51 
54 
57 
60 
63 
66 
69 
71  mutable bool has_positional_info;
72 
87  mutable int pending_reply = -1;
88 
90  mutable string uuid;
91 
93  string context;
94 
95  mutable bool cached_stats_valid;
96 
99 
105 
112  mutable bool uncommitted_changes = false;
113 
114  bool update_stats(message_type msg_code = MSG_UPDATE,
115  const std::string & body = std::string()) const;
116 
117  protected:
132  RemoteDatabase(int fd, double timeout_, const string & context_,
133  bool writable, int flags);
134 
136  reply_type get_message(std::string& message,
137  reply_type required_type,
138  reply_type required_type2) const;
139 
140  void get_message(std::string& message,
141  reply_type required_type) const {
142  (void)get_message(message, required_type, required_type);
143  }
144 
145  bool get_message_or_done(std::string& message,
146  reply_type required_type) const {
147  return get_message(message, required_type, REPLY_DONE) != REPLY_DONE;
148  }
149 
151  void send_message(message_type type, const string & data) const;
152 
154  void do_close();
155 
156  bool get_posting(Xapian::docid &did, double &w, string &value);
157 
159  double timeout;
160 
161  public:
163  void keep_alive();
164 
185  void set_query(const Xapian::Query& query,
186  Xapian::termcount qlen,
187  Xapian::doccount collapse_max,
188  Xapian::valueno collapse_key,
190  Xapian::valueno sort_key,
192  bool sort_value_forward,
193  double time_limit,
194  int percent_cutoff, double weight_cutoff,
195  const Xapian::Weight *wtscheme,
196  const Xapian::RSet &omrset,
197  const vector<Xapian::Internal::opt_intrusive_ptr<Xapian::MatchSpy>> & matchspies);
198 
203  bool get_remote_stats(bool nowait, Xapian::Weight::Internal &out);
204 
207  Xapian::doccount maxitems,
208  Xapian::doccount check_at_least,
209  const Xapian::Weight::Internal &stats);
210 
212  void get_mset(Xapian::MSet &mset,
213  const vector<Xapian::Internal::opt_intrusive_ptr<Xapian::MatchSpy>> & matchspies);
214 
216  TermList * open_metadata_keylist(const std::string & prefix) const;
217 
220 
222  TermList * open_allterms(const string & prefix) const;
223 
224  bool has_positions() const;
225 
226  bool reopen();
227 
228  void close();
229 
230  LeafPostList * open_post_list(const string & tname) const;
231 
232  Xapian::doccount read_post_list(const string &term, NetworkPostList & pl) const;
233 
235  const string & tname) const;
236 
239 
242 
245 
247 
250 
252  bool term_exists(const string & tname) const;
253 
254  void get_freqs(const string & term,
255  Xapian::doccount * termfreq_ptr,
256  Xapian::termcount * collfreq_ptr) const;
257 
259  void read_value_stats(Xapian::valueno slot) const;
261  std::string get_value_lower_bound(Xapian::valueno slot) const;
262  std::string get_value_upper_bound(Xapian::valueno slot) const;
263 
266  Xapian::termcount get_wdf_upper_bound(const string & term) const;
267 
268  void commit();
269 
270  void cancel();
271 
273 
274  void delete_document(Xapian::docid did);
275  void delete_document(const std::string & unique_term);
276 
277  void replace_document(Xapian::docid did, const Xapian::Document & doc);
278  Xapian::docid replace_document(const std::string & unique_term,
279  const Xapian::Document & document);
280 
281  std::string get_uuid() const;
282 
283  string get_metadata(const string & key) const;
284 
285  void set_metadata(const string & key, const string & value);
286 
287  void add_spelling(const std::string&, Xapian::termcount) const;
288 
289  void remove_spelling(const std::string&, Xapian::termcount freqdec) const;
290 
291  int get_backend_info(string * path) const {
292  if (path) *path = context;
293  return BACKEND_REMOTE;
294  }
295 
296  bool locked() const;
297 };
298 
299 #endif // XAPIAN_INCLUDED_REMOTE_DATABASE_H
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
Definition: api_anydb.cc:63
database class declarations
BACKEND_* constants.
@ BACKEND_REMOTE
Definition: backends.h:26
Abstract base class for leaf postlists.
Definition: leafpostlist.h:39
A postlist in a remote database.
Definition: net_postlist.h:36
RemoteConnection which owns its own fd(s).
RemoteDatabase is the baseclass for remote database implementations.
bool get_message_or_done(std::string &message, reply_type required_type) const
Xapian::doccount doccount
The remote document count, given at open.
bool locked() const
Return true if the database is open for writing.
RemoteDatabase(const RemoteDatabase &)
Don't allow copying.
bool update_stats(message_type msg_code=MSG_UPDATE, const std::string &body=std::string()) const
void operator=(const RemoteDatabase &)
Don't allow assignment.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique term in document.
bool has_positional_info
Has positional information?
void do_close()
Close the socket.
void cancel()
Cancel pending modifications to the database.
void send_message(message_type type, const string &data) const
Send a message to the server.
void get_message(std::string &message, reply_type required_type) const
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
TermList * open_term_list(Xapian::docid did) const
Get remote termlist.
Xapian::termcount doclen_lbound
A lower bound on the smallest document length in this database.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a given document.
void set_metadata(const string &key, const string &value)
Set the metadata associated with a given key.
void delete_document(Xapian::docid did)
Delete a document in the database.
TermList * open_allterms(const string &prefix) const
Iterate all terms.
bool has_positions() const
Check whether this database contains any positional information.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Get a remote document.
int get_backend_info(string *path) const
Get backend information about this database.
bool uncommitted_changes
True if there are (or may be) uncommitted changes.
Xapian::valueno mru_slot
The value slot for the most recently used value statistics.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
bool get_remote_stats(bool nowait, Xapian::Weight::Internal &out)
Get the stats from the remote server.
int pending_reply
Are we currently expecting a reply?
string get_metadata(const string &key) const
Get the metadata associated with a given key.
bool reopen()
Reopen the database to the latest available revision.
double timeout
The timeout value used in network communications, in seconds.
OwnedRemoteConnection link
The object which does the I/O.
void keep_alive()
Send a keep-alive message.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
ValueStats mru_valstats
The most recently used value statistics.
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
Xapian::docid add_document(const Xapian::Document &doc)
Add a new document to the database.
void add_spelling(const std::string &, Xapian::termcount) const
Add a word to the spelling dictionary.
reply_type get_message(std::string &message, reply_type required_type, reply_type required_type2) const
Receive a message from the server.
void read_value_stats(Xapian::valueno slot) const
Read the value statistics for a value from a remote database.
std::string get_uuid() const
Get a UUID for the database.
Xapian::docid get_lastdocid() const
Get the last used docid.
LeafPostList * open_post_list(const string &tname) const
Open a posting list.
void remove_spelling(const std::string &, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
string context
The context to return with any error messages.
void commit()
Commit pending modifications to the database.
void replace_document(Xapian::docid did, const Xapian::Document &doc)
Replace a given document in the database.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
string uuid
The UUID of the remote database.
Xapian::doccount read_post_list(const string &term, NetworkPostList &pl) const
Xapian::totallength total_length
The total length of all documents in this database.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
Xapian::doccount get_doccount() const
Get the document count.
Xapian::docid lastdocid
The remote last docid, given at open.
Xapian::termcount get_wdf_upper_bound(const string &term) const
Get an upper bound on the wdf of term term.
void get_mset(Xapian::MSet &mset, const vector< Xapian::Internal::opt_intrusive_ptr< Xapian::MatchSpy >> &matchspies)
Get the MSet from the remote server.
bool get_posting(Xapian::docid &did, double &w, string &value)
void send_global_stats(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount check_at_least, const Xapian::Weight::Internal &stats)
Send the global stats to the remote server.
bool term_exists(const string &tname) const
Check if term exists.
TermList * open_metadata_keylist(const std::string &prefix) const
Get remote metadata key list.
PositionList * open_position_list(Xapian::docid did, const string &tname) const
Open a position list for the given term in the given document.
void close()
Close the database.
Xapian::termcount doclen_ubound
An upper bound on the greatest document length in this database.
void set_query(const Xapian::Query &query, Xapian::termcount qlen, Xapian::doccount collapse_max, Xapian::valueno collapse_key, Xapian::Enquire::docid_order order, Xapian::valueno sort_key, Xapian::Enquire::Internal::sort_setting sort_by, bool sort_value_forward, double time_limit, int percent_cutoff, double weight_cutoff, const Xapian::Weight *wtscheme, const Xapian::RSet &omrset, const vector< Xapian::Internal::opt_intrusive_ptr< Xapian::MatchSpy >> &matchspies)
Set the query.
Base class for databases.
Definition: database.h:57
A document in the database, possibly plus modifications.
Definition: document.h:43
A handle representing a document in a Xapian database.
Definition: document.h:61
docid_order
Ordering of docids.
Definition: enquire.h:326
Class representing a list of search results.
Definition: mset.h:44
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Class representing a query.
Definition: query.h:46
A relevance set (R-Set).
Definition: enquire.h:60
Abstract base class for termlists.
Definition: termlist.h:39
Class to hold statistics for a given collection.
Abstract base class for weighting schemes.
Definition: weight.h:35
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Definition: types.h:139
Xapian::Query internals.
RemoteConnection class used by the remote backend.
message_type
Message types (client -> server).
@ MSG_UPDATE
reply_type
Reply types (server -> client).
@ REPLY_DONE
Class to hold statistics for a given slot.
Definition: valuestats.h:29
Statistics about values.
Weighting scheme API.