51 #include <string_view>
97 :
Xapian::Database::Internal(writable ?
99 TRANSACTION_READONLY),
100 link(fd_and_context.first, fd_and_context.first, fd_and_context.second),
101 cached_stats_valid(),
121 std::string_view
term)
const
132 const char *
p = message.data();
133 const char * p_end =
p + message.size();
172 const char *
p = message.c_str();
173 const char * p_end =
p + message.size();
219 const char *
p = message.data();
220 const char * p_end =
p + message.size();
257 const char*
p = message.data();
258 const char* p_end =
p + message.size();
325 map<Xapian::valueno, string> values;
327 const char *
p = message.data();
328 const char * p_end =
p + message.size();
333 values.insert(make_pair(slot,
string(
p, p_end)));
354 if (message.size() < 3) {
357 const char *
p = message.c_str();
358 const char *p_end =
p + message.size();
362 int protocol_major =
static_cast<unsigned char>(*
p++);
363 int protocol_minor =
static_cast<unsigned char>(*
p++);
366 string errmsg(
"Server supports protocol version");
367 if (protocol_minor) {
369 errmsg +=
str(protocol_major);
374 errmsg +=
str(protocol_major);
376 errmsg +=
str(protocol_minor);
378 " - client is using "
396 uuid.assign(
p, p_end);
443 if (termfreq_ptr && collfreq_ptr) {
446 const char*
p = message.data();
447 const char* p_end =
p + message.size();
452 }
else if (termfreq_ptr) {
455 const char*
p = message.data();
456 const char* p_end =
p + message.size();
460 }
else if (collfreq_ptr) {
463 const char*
p = message.data();
464 const char* p_end =
p + message.size();
487 const char*
p = message.data();
488 const char* p_end =
p + message.size();
549 const char*
p = message.c_str();
550 const char* p_end =
p + message.size();
567 const char*
p = message.c_str();
568 const char* p_end =
p + message.size();
585 const char*
p = message.c_str();
586 const char* p_end =
p + message.size();
609 string errmsg(
"Invalid reply type ");
616 if (type != required_type && type != required_type2) {
617 string errmsg(
"Expecting reply type ");
618 errmsg +=
str(
int(required_type));
619 if (required_type2 != required_type) {
621 errmsg +=
str(
int(required_type2));
684 bool sort_value_forward,
686 int percent_threshold,
double weight_threshold,
689 const vector<opt_ptr_spy>& matchspies)
const
697 if (collapse_max)
pack_uint(message, collapse_key);
698 message += char(order);
699 message += char(sort_by);
705 message += char(percent_threshold);
714 for (
auto i : matchspies) {
715 const string&
name = i->name();
717 throw Xapian::UnimplementedError(
"MatchSpy subclass not suitable for use with remote searches - name() method returned empty string");
731 const char*
p = message.data();
734 total += remote_stats;
751 const string&
name = sorter->
name();
767 const char *
p = message.data();
768 const char * p_end =
p + message.size();
771 for (
auto i : matchspies) {
775 i->merge_results(spyresults);
823 const char*
p = message.data();
824 const char* p_end =
p + message.size();
891 const char*
p = message.data();
892 const char* p_end =
p + message.size();
964 const char *
p = message.data();
965 const char * p_end =
p + message.size();
1054 string desc =
"Remote(context=";
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())
A PostList iterating all docids when they form a contiguous range.
PositionList from an InMemory DB or a Document object.
Abstract base class for leaf postlists.
A postlist in a remote database.
Iterate all terms in a remote database.
void send_message(char type, std::string_view s, double end_time)
Send a message.
const std::string & get_context() const
Return the context to report with errors.
void do_close()
Close the connection.
int get_message(std::string &result, double end_time)
Read one message from fdin.
void shutdown()
Shutdown the connection.
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
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.
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.
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.
void remove_synonym(std::string_view word, std::string_view synonym) const
Remove a synonym for a term.
void add_synonym(std::string_view word, std::string_view synonym) const
Add a synonym for a term.
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.
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.
A document read from a RemoteDatabase.
Iterate keys in a remote database.
Iterate terms in a remote document.
bool is_read_only() const
Test if this shard is read-only.
bool transaction_active() const
Test if a transaction is currently active.
virtual void end_transaction(bool do_commit)
End transaction.
Abstract base class for a document.
Class representing a document.
docid_order
Ordering of docids.
Abstract base class for postlists.
A smart pointer that uses intrusive reference counting.
InvalidOperationError indicates the API was used in an invalid way.
Virtual base class for key making functors.
virtual std::string serialise() const
Return this object's parameters serialised as a single string.
virtual std::string name() const
Return the name of this KeyMaker.
Class representing a list of search results.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Indicates a problem communicating with a remote database.
Abstract base class for iterating term positions in a document.
Class representing a query.
std::string serialise() const
Serialise this object into a string.
Class representing a set of documents judged as relevant.
Abstract base class for termlists.
UnimplementedError indicates an attempt to use an unimplemented feature.
Suitable for "simple" type T.
Class to hold statistics for a given collection.
Abstract base class for weighting schemes.
virtual std::string name() const
Return the name of this weighting scheme, e.g.
virtual std::string serialise() const
Return this object's parameters serialised as a single string.
#define UNSIGNED_OVERFLOW_OK(X)
Constants in the Xapian namespace.
Iterate all document ids when they form a contiguous range.
Hierarchy of classes which Xapian can throw as exceptions.
PositionList from an InMemory DB or a Document object.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
string str(int value)
Convert int to std::string.
The Xapian namespace contains public interfaces for the Xapian library.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
const int DB_RETRY_LOCK
If the database is already locked, retry the lock.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
Postlists for remote databases.
Various assertion macros.
void unpack_throw_serialisation_error(const char *p)
Throw appropriate SerialisationError.
Pack types into strings and unpack them again.
bool unpack_uint_last(const char **p, const char *end, U *result)
Decode an unsigned integer as the last item in a string.
bool unpack_string(const char **p, const char *end, std::string &result)
Decode a std::string from a string.
void pack_uint_last(std::string &s, U value)
Append an encoded unsigned integer to a string as the last item.
bool unpack_bool(const char **p, const char *end, bool *result)
Decode a bool from a string.
void pack_bool(std::string &s, bool value)
Append an encoded bool to a string.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
void pack_string(std::string &s, std::string_view value)
Append an encoded std::string to a string.
void pack_string_empty(std::string &s)
Append an empty encoded std::string to a string.
Functions for handling a time or time interval in a double.
static void throw_handshake_failed(const string &context)
static void throw_invalid_operation(const char *message)
static void throw_connection_closed_unexpectedly()
static bool is_intermediate_reply(int reply_code)
Return true if further replies should be expected.
RemoteDatabase is the baseclass for remote database implementations.
A document read from a RemoteDatabase.
Iterate all terms in a remote database.
Iterate keys in a remote database.
Iterate terms in a remote document.
#define XAPIAN_REMOTE_PROTOCOL_MAJOR_VERSION
message_type
Message types (client -> server).
@ MSG_REPLACEDOCUMENTTERM
reply_type
Reply types (server -> client).
@ REPLY_POSITIONLISTCOUNT
#define XAPIAN_REMOTE_PROTOCOL_MINOR_VERSION
include <sys/socket.h> with portability workarounds.
string serialise_double(double v)
Serialise a double to a string.
functions to serialise and unserialise a double
void unserialise_error(const string &serialised_error, const string &prefix, const string &new_context)
Unserialise a Xapian::Error object and throw it.
functions to convert classes to strings and back
string serialise_document(const Xapian::Document &doc)
Serialise a Xapian::Document object.
string serialise_stats(const Xapian::Weight::Internal &stats)
Serialise a stats object.
void unserialise_stats(const char *p, const char *p_end, Xapian::Weight::Internal &stat)
Unserialise a serialised stats object.
string serialise_rset(const Xapian::RSet &rset)
Serialise a Xapian::RSet object.
functions to convert classes to strings and back
Custom vector implementations using small vector optimisation.
Convert types to std::string.
Various handy string-related helpers.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
std::string lower_bound
A lower bound on the values stored in the given value slot.
std::string upper_bound
An upper bound on the values stored in the given value slot.
Xapian::doccount freq
The number of documents which have a (non-empty) value stored in the slot.
Xapian::Weight::Internal class, holding database and term statistics.