xapian-core  2.0.0
remote-database.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006-2024 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, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_REMOTE_DATABASE_H
23 #define XAPIAN_INCLUDED_REMOTE_DATABASE_H
24 
25 #include "backends/backends.h"
27 #include "api/enquireinternal.h"
28 #include "api/queryinternal.h"
29 #include "net/remoteconnection.h"
30 #include "backends/valuestats.h"
31 #include "xapian/weight.h"
32 
33 #include <utility>
34 
35 namespace Xapian {
36  class RSet;
37 }
38 
39 class NetworkPostList;
40 
49  void operator=(const RemoteDatabase &);
50 
53 
56 
59 
62 
65 
68 
71 
73  mutable bool has_positional_info;
74 
83  mutable bool pending_reply = false;
84 
86  mutable std::string uuid;
87 
88  mutable bool cached_stats_valid;
89 
92 
98 
105  mutable bool uncommitted_changes = false;
106 
107  bool update_stats(message_type msg_code = MSG_UPDATE,
108  const std::string & body = std::string()) const;
109 
110  protected:
129  RemoteDatabase(std::pair<int, std::string> fd_and_context,
130  double timeout_,
131  bool writable,
132  int flags);
133 
135  reply_type get_message(std::string& message,
136  reply_type required_type,
137  reply_type required_type2) const;
138 
139  void get_message(std::string& message,
140  reply_type required_type) const {
141  (void)get_message(message, required_type, required_type);
142  }
143 
144  bool get_message_or_done(std::string& message,
145  reply_type required_type) const {
146  return get_message(message, required_type, REPLY_DONE) != REPLY_DONE;
147  }
148 
150  void send_message(message_type type, std::string_view data) const;
151 
153  void do_close();
154 
155  bool get_posting(Xapian::docid& did, double& w, std::string& value);
156 
158  double timeout;
159 
160  public:
166  std::string_view term) const;
167 
169  void keep_alive();
170 
172 
193  void set_query(const Xapian::Query& query,
194  Xapian::termcount qlen,
195  Xapian::valueno collapse_key,
196  Xapian::doccount collapse_max,
198  Xapian::valueno sort_key,
200  bool sort_value_forward,
201  double time_limit,
202  int percent_threshold, double weight_threshold,
203  const Xapian::Weight& wtscheme,
204  const Xapian::RSet &omrset,
205  const std::vector<opt_ptr_spy>& matchspies) const;
206 
212  int get_read_fd() const {
213  return link.get_read_fd();
214  }
215 
218 
221  Xapian::doccount maxitems,
222  Xapian::doccount check_at_least,
223  const Xapian::KeyMaker* sorter,
224  const Xapian::Weight::Internal &stats) const;
225 
227  Xapian::MSet get_mset(const std::vector<opt_ptr_spy>& matchspies) const;
228 
230  TermList* open_metadata_keylist(std::string_view prefix) const;
231 
234 
236 
238  TermList* open_allterms(std::string_view prefix) const;
239 
240  bool has_positions() const;
241 
242  bool reopen();
243 
244  void close();
245 
246  PostList* open_post_list(std::string_view term) const;
247 
248  LeafPostList* open_leaf_post_list(std::string_view term, bool) const;
249 
250  Xapian::doccount read_post_list(const std::string& term, NetworkPostList & pl) const;
251 
253  std::string_view tname) const;
254 
257 
260 
263 
265 
269 
271  bool term_exists(std::string_view term) const;
272 
273  void get_freqs(std::string_view term,
274  Xapian::doccount* termfreq_ptr,
275  Xapian::termcount* collfreq_ptr) const;
276 
278  void read_value_stats(Xapian::valueno slot) const;
280  std::string get_value_lower_bound(Xapian::valueno slot) const;
281  std::string get_value_upper_bound(Xapian::valueno slot) const;
282 
285  Xapian::termcount get_wdf_upper_bound(std::string_view term) const;
286 
287  void commit();
288 
289  void cancel();
290 
292 
293  void delete_document(Xapian::docid did);
294  void delete_document(std::string_view unique_term);
295 
296  void replace_document(Xapian::docid did, const Xapian::Document & doc);
297  Xapian::docid replace_document(std::string_view unique_term,
298  const Xapian::Document& document);
299 
300  std::string get_uuid() const;
301 
302  std::string get_metadata(std::string_view key) const;
303 
304  void set_metadata(std::string_view key, std::string_view value);
305 
306  void request_document(Xapian::docid did) const;
307 
308  void add_spelling(std::string_view word, Xapian::termcount freqinc) const;
309 
310  TermList* open_synonym_termlist(std::string_view term) const;
311 
312  TermList* open_synonym_keylist(std::string_view prefix) const;
313 
314  void add_synonym(std::string_view word, std::string_view synonym) const;
315 
316  void remove_synonym(std::string_view word,
317  std::string_view synonym) const;
318 
319  void clear_synonyms(std::string_view word) const;
320 
321  Xapian::termcount remove_spelling(std::string_view word,
322  Xapian::termcount freqdec) const;
323 
324  int get_backend_info(std::string* path) const {
325  if (path) *path = link.get_context();
326  return BACKEND_REMOTE;
327  }
328 
329  bool locked() const;
330 
331  std::string reconstruct_text(Xapian::docid did,
332  size_t length,
333  std::string_view prefix,
334  Xapian::termpos start_pos,
335  Xapian::termpos end_pos) const;
336 
337  std::string get_description() const;
338 };
339 
340 #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:62
BACKEND_* constants.
@ BACKEND_REMOTE
Definition: backends.h:27
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
A postlist in a remote database.
Definition: net_postlist.h:35
RemoteConnection which owns its own fd(s).
const std::string & get_context() const
Return the context to report with errors.
int get_read_fd() const
Return the underlying fd this remote connection reads from.
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.
void set_metadata(std::string_view key, std::string_view value)
Set the metadata associated with a given key.
bool locked() const
Return true if the database is open for writing.
LeafPostList * open_leaf_post_list(std::string_view term, bool) const
Create a LeafPostList for use during a match.
void set_query(const Xapian::Query &query, Xapian::termcount qlen, Xapian::valueno collapse_key, Xapian::doccount collapse_max, 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_threshold, double weight_threshold, const Xapian::Weight &wtscheme, const Xapian::RSet &omrset, const std::vector< opt_ptr_spy > &matchspies) const
Set the query.
TermList * open_synonym_keylist(std::string_view prefix) const
Open a termlist returning each term which has synonyms.
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.
TermList * open_allterms(std::string_view prefix) const
Iterate all terms.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
bool has_positional_info
Has positional information?
void clear_synonyms(std::string_view word) const
Clear all synonyms for a term.
std::string uuid
The UUID of the remote database.
void do_close()
Close the socket.
void send_global_stats(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount check_at_least, const Xapian::KeyMaker *sorter, const Xapian::Weight::Internal &stats) const
Send the global stats to the remote server.
void cancel()
Cancel pending modifications to the database.
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_synonym_termlist(std::string_view term) const
Open a termlist returning synonyms for a term.
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
TermList * open_metadata_keylist(std::string_view prefix) const
Get remote metadata key list.
PositionList * open_position_list(Xapian::docid did, std::string_view tname) const
void delete_document(Xapian::docid did)
bool pending_reply
Are we currently expecting a reply?
std::string get_metadata(std::string_view key) const
Get the metadata associated with a given key.
void request_document(Xapian::docid did) const
Request a document.
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.
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.
Xapian::doccount read_post_list(const std::string &term, NetworkPostList &pl) const
bool term_exists(std::string_view term) const
Check if term exists.
Xapian::termcount get_wdf_upper_bound(std::string_view term) const
Get an upper bound on the wdf of term term.
bool reopen()
Reopen the database to the latest available revision.
Xapian::Internal::opt_intrusive_ptr< Xapian::MatchSpy > opt_ptr_spy
void remove_synonym(std::string_view word, std::string_view synonym) const
Remove a synonym for a term.
bool get_posting(Xapian::docid &did, double &w, std::string &value)
int get_backend_info(std::string *path) const
Get backend information about this database.
void add_synonym(std::string_view word, std::string_view synonym) const
Add a synonym for a term.
RemoteDatabase(std::pair< int, std::string > fd_and_context, double timeout_, bool writable, int flags)
Constructor.
double timeout
The timeout value used in network communications, in seconds.
OwnedRemoteConnection link
The object which does the I/O.
TermList * open_term_list_direct(Xapian::docid did) const
Like open_term_list() but without MultiTermList wrapper.
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.
void get_freqs(std::string_view term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
void add_spelling(std::string_view word, Xapian::termcount freqinc) const
Add a word to the spelling dictionary.
int get_read_fd() const
Get the underlying fd this remote connection reads from.
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
Xapian::docid add_document(const Xapian::Document &doc)
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.
std::string reconstruct_text(Xapian::docid did, size_t length, std::string_view prefix, Xapian::termpos start_pos, Xapian::termpos end_pos) const
void commit()
Commit pending modifications to the database.
void replace_document(Xapian::docid did, const Xapian::Document &doc)
std::string get_description() const
Return a string describing this object.
Xapian::termcount remove_spelling(std::string_view word, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
PostList * open_post_list(std::string_view term) const
Return a PostList suitable for use in a PostingIterator.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
Xapian::MSet get_mset(const std::vector< opt_ptr_spy > &matchspies) const
Get the MSet from the remote server.
void send_message(message_type type, std::string_view data) const
Send a message to the server.
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::termcount get_wdfdocmax(Xapian::docid did) const
Get the max wdf in document.
Xapian::doccount get_doccount() const
Get the document count.
Xapian::docid lastdocid
The remote last docid, given at open.
Xapian::termcount positionlist_count(Xapian::docid did, std::string_view term) const
Get the length of the position list.
void close()
Close the database.
Xapian::termcount doclen_ubound
An upper bound on the greatest document length in this database.
void accumulate_remote_stats(Xapian::Weight::Internal &total) const
Accumulate stats from the remote server.
Virtual base class for Database internals.
Abstract base class for a document.
Class representing a document.
Definition: document.h:64
docid_order
Ordering of docids.
Definition: enquire.h:130
Abstract base class for postlists.
Definition: postlist.h:40
Virtual base class for key making functors.
Definition: keymaker.h:44
Class representing a list of search results.
Definition: mset.h:46
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Class representing a query.
Definition: query.h:45
Class representing a set of documents judged as relevant.
Definition: rset.h:39
Abstract base class for termlists.
Definition: termlist.h:42
Class to hold statistics for a given collection.
Abstract base class for weighting schemes.
Definition: weight.h:38
string term
Virtual base class for Database internals.
Xapian::Enquire internals.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Definition: types.h:114
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:28
Statistics about values.
Weighting scheme API.