87 const string & context_,
bool writable,
89 :
link(fd, fd, context_),
109 const string & body =
encode_length(flags & Xapian::DB_RETRY_LOCK);
134 AutoPtr<NetworkTermList> tlist(
138 vector<NetworkTermListItem> & items = tlist->items;
140 string term = prefix;
143 term.resize(
size_t(static_cast<unsigned char>(message[0])));
144 term.append(message, 1, string::npos);
146 items.push_back(item);
149 tlist->current_position = tlist->items.begin();
150 return tlist.release();
165 const char * p = message.c_str();
166 const char * p_end = p + message.size();
173 AutoPtr<NetworkTermList> tlist(
177 vector<NetworkTermListItem> & items = tlist->items;
183 p_end = p + message.size();
186 term.resize(
size_t(static_cast<unsigned char>(*p++)));
187 term.append(p, p_end);
189 items.push_back(item);
192 tlist->current_position = tlist->items.begin();
193 return tlist.release();
203 AutoPtr<NetworkTermList> tlist(
207 vector<NetworkTermListItem> & items = tlist->items;
209 string term = prefix;
213 const char * p = message.data();
214 const char * p_end = p + message.size();
216 term.resize(
size_t(static_cast<unsigned char>(*p++)));
217 term.append(p, p_end);
219 items.push_back(item);
222 tlist->current_position = tlist->items.begin();
223 return tlist.release();
240 const char * p = message.data();
241 const char * p_end = p + message.size();
257 vector<Xapian::termpos> positions;
262 const char * p = message.data();
263 const char * p_end = p + message.size();
267 positions.push_back(lastpos);
322 map<Xapian::valueno, string> values;
327 const char * p = message.data();
328 const char * p_end = p + message.size();
331 values.insert(make_pair(slot,
string(p, p_end)));
351 if (message.size() < 3) {
354 const char *p = message.c_str();
355 const char *p_end = p + message.size();
359 int protocol_major =
static_cast<unsigned char>(*p++);
360 int protocol_minor =
static_cast<unsigned char>(*p++);
363 string errmsg(
"Server supports protocol version");
364 if (protocol_minor) {
366 errmsg +=
str(protocol_major);
371 errmsg +=
str(protocol_major);
373 errmsg +=
str(protocol_minor);
375 " - client is using " 393 uuid.assign(p, p_end);
449 p_end = p + message.size();
451 }
else if (collfreq_ptr) {
455 p_end = p + message.size();
469 const char * p = message.data();
470 const char * p_end = p + message.size();
536 const char * p = message.c_str();
537 const char * p_end = p + message.size();
553 const char * p = message.c_str();
554 const char * p_end = p + message.size();
578 string errmsg(
"Invalid reply type ");
585 if (type != required_type && type != required_type2) {
586 string errmsg(
"Expecting reply type ");
587 errmsg +=
str(
int(required_type));
588 if (required_type2 != required_type) {
590 errmsg +=
str(
int(required_type2));
664 bool sort_value_forward,
666 int percent_cutoff,
double weight_cutoff,
679 message += char(
'0' + order);
681 message += char(
'0' + sort_by);
682 message += char(
'0' + sort_value_forward);
684 message += char(percent_cutoff);
687 tmp = wtscheme->
name();
699 for (
auto i : matchspies) {
702 throw Xapian::UnimplementedError(
"MatchSpy subclass not suitable for use with remote searches - name() method returned empty string");
707 tmp = i->serialise();
722 const char* p = message.data();
747 const char * p = message.data();
748 const char * p_end = p + message.size();
750 for (
auto i : matchspies) {
755 string spyresults(p, len);
757 i->merge_results(spyresults);
803 const char * p = message.data();
804 const char * p_end = p + message.size();
859 message += unique_term;
866 const char * p = message.data();
867 const char * p_end = p + message.size();
void close()
Close the database.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Returns frequencies for a term.
An item in a NetworkTermList.
The Xapian namespace contains public interfaces for the Xapian library.
PositionList from an InMemory DB or a Document object.
Define the XAPIAN_NORETURN macro.
LeafPostList * open_post_list(const string &tname) const
Open a posting list.
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a given document.
TermList * open_metadata_keylist(const std::string &prefix) const
Get remote metadata key list.
bool uncommitted_changes
True if there are (or may be) uncommitted changes.
length encoded as a string
int get_message(std::string &result, double end_time)
Read one message from fdin.
Xapian::doccount doccount
The remote document count, given at open.
unsigned timeout
A timeout value in milliseconds.
static void throw_handshake_failed(const string &context)
virtual std::string name() const
Return the name of this weighting scheme.
bool transaction_active() const
Xapian::termcount wdf
The within-document-frequency of the term.
void read_value_stats(Xapian::valueno slot) const
Read the value statistics for a value from a remote database.
bool has_positional_info
Has positional information?
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
include <sys/socket.h> with portability workarounds.
Constants in the Xapian namespace.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
TermList * open_allterms(const string &prefix) const
Iterate all terms.
reply_type
Reply types (server -> client).
string context
The context to return with any error messages.
A document in the database, possibly plus modifications.
Class representing a list of search results.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
RemoteDatabase is the baseclass for remote database implementations.
Abstract base class for termlists.
Convert types to std::string.
Xapian::termcount get_wdf_upper_bound(const string &term) const
Get an upper bound on the wdf of term term.
bool has_positions() const
Check whether this database contains any positional information.
std::string upper_bound
An upper bound on the values stored in the given value slot.
Abstract base class for leaf postlists.
Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const
Get a remote document.
virtual std::string serialise() const
Return this object's parameters serialised as a single string.
std::string encode_length(T len)
Encode a length as a variable-length string.
Xapian::docid get_lastdocid() const
Get the last used docid.
static bool is_intermediate_reply(int msg_code, int reply_code)
Return true if further replies should be expected.
Xapian::docid add_document(const Xapian::Document &doc)
Add a new document to the database.
void send_message(message_type type, const string &data) const
Send a message to the server.
double timeout
The timeout value used in network communications, in seconds.
void do_close()
Close the socket.
void delete_document(Xapian::docid did)
Delete a document in the database.
int pending_reply
Are we currently expecting a reply?
Xapian::totallength total_length
The total length of all documents in this database.
Xapian::doccount termfreq
The term frequency.
Xapian::doccount freq
The number of documents which have a (non-empty) value stored in the slot.
ValueStats mru_valstats
The most recently used value statistics.
std::string lower_bound
A lower bound on the values stored in the given value slot.
enum Xapian::Database::Internal::@2 transaction_state
Transaction state.
Xapian::doccount get_doccount() const
Get the document count.
Xapian::MSet unserialise_mset(const char *p, const char *p_end)
Unserialise a serialised Xapian::MSet object.
Hierarchy of classes which Xapian can throw as exceptions.
void commit()
Commit pending modifications to the database.
Xapian::docid lastdocid
The remote last docid, given at open.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
void unserialise_error(const string &serialised_error, const string &prefix, const string &new_context)
Unserialise a Xapian::Error object and throw it.
functions to serialise and unserialise a double
string get_metadata(const string &key) const
Get the metadata associated with a given key.
OwnedRemoteConnection link
The object which does the I/O.
Xapian::termcount doclen_lbound
A lower bound on the smallest document length in this database.
Xapian::Weight::Internal class, holding database and term statistics.
void get_mset(Xapian::MSet &mset, const vector< Xapian::Internal::opt_intrusive_ptr< Xapian::MatchSpy >> &matchspies)
Get the MSet from the remote server.
Class to hold statistics for a given collection.
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.
string uuid
The UUID of the remote database.
Xapian::valueno mru_slot
The value slot for the most recently used value statistics.
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.
string str(int value)
Convert int to std::string.
A position list in a inmemory database.
bool get_remote_stats(bool nowait, Xapian::Weight::Internal &out)
Get the stats from the remote server.
std::string serialise() const
Serialise this object into a string.
bool term_exists(const string &tname) const
Check if term exists.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
Postlists for remote databases.
#define XAPIAN_REMOTE_PROTOCOL_MAJOR_VERSION
void keep_alive()
Send a keep-alive message.
string serialise_stats(const Xapian::Weight::Internal &stats)
Serialise a stats object.
void replace_document(Xapian::docid did, const Xapian::Document &doc)
Replace a given document in the database.
functions to convert classes to strings and back
string serialise_rset(const Xapian::RSet &rset)
Serialise a Xapian::RSet object.
#define XAPIAN_REMOTE_PROTOCOL_MINOR_VERSION
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())
string serialise_document(const Xapian::Document &doc)
Serialise a Xapian::Document object.
bool update_stats(message_type msg_code=MSG_UPDATE, const std::string &body=std::string()) const
void unserialise_stats(const char *p, const char *p_end, Xapian::Weight::Internal &stat)
Unserialise a serialised stats object.
void set_metadata(const string &key, const string &value)
Set the metadata associated with a given key.
std::string serialise_double(double v)
Serialise a double to a string.
void decode_length_and_check(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique term in document.
A document read from a RemoteDatabase.
void shutdown()
Shutdown the connection.
void remove_spelling(const std::string &, Xapian::termcount freqdec) const
Remove a word from the spelling dictionary.
A term list for a database on the other side of a network connection.
PositionList * open_position_list(Xapian::docid did, const string &tname) const
Open a position list for the given term in the given document.
bool locked() const
Return true if the database is open for writing.
Indicates a problem communicating with a remote database.
void add_spelling(const std::string &, Xapian::termcount) const
Add a word to the spelling dictionary.
Xapian::doccount read_post_list(const string &term, NetworkPostList &pl) const
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
string tname
The "name" of this term.
Various handy helpers which std::string really should provide.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
message_type
Message types (client -> server).
std::string get_uuid() const
Get a UUID for the database.
void send_message(char type, const std::string &s, double end_time)
Send a message.
A document read from a RemoteDatabase.
const int DB_RETRY_LOCK
If the database is already locked, retry the lock.
Xapian::totallength get_total_length() const
Return the total length of all documents in this database.
static void throw_connection_closed_unexpectedly()
Various assertion macros.
bool reopen()
Reopen the database to the latest available revision.
Functions for handling a time or time interval in a double.
bool ready_to_read() const
See if there is data available to read.
bool get_message_or_done(std::string &message, reply_type required_type) const
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
void cancel()
Cancel pending modifications to the database.
Class representing a query.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
Abstract base class for iterating term positions in a document.
A smart pointer that uses intrusive reference counting.
void do_close()
Close the connection.
functions to convert classes to strings and back
reply_type get_message(std::string &message, reply_type required_type, reply_type required_type2) const
Receive a message from the server.
docid_order
Ordering of docids.
void cancel_transaction()
Cancel a transaction.
A postlist in a remote database.
void decode_length(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
A handle representing a document in a Xapian database.
Wrapper around standard unique_ptr template.
void append_posting(const string &serialised)
Append a posting to the end of the postlist.
UnimplementedError indicates an attempt to use an unimplemented feature.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
Abstract base class for weighting schemes.
Xapian::termcount doclen_ubound
An upper bound on the greatest document length in this database.
RemoteDatabase(const RemoteDatabase &)
Don't allow copying.
TermList * open_term_list(Xapian::docid did) const
Get remote termlist.