65 int fdin_,
int fdout_,
66 double active_timeout_,
double idle_timeout_,
70 active_timeout(active_timeout_), idle_timeout(idle_timeout_)
84 vector<string>::const_iterator i(dbpaths.begin());
85 for (++i; i != dbpaths.end(); ++i) {
105 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
134 string errmsg(
"Invalid message type ");
138 if (required_type !=
MSG_MAX && type !=
int(required_type)) {
139 string errmsg(
"Expecting message type ");
140 errmsg +=
str(
int(required_type));
152 unsigned char type_as_char =
static_cast<unsigned char>(type);
283 string errmsg(
"Unexpected message type ");
326 string prev = message;
327 const string& prefix = message;
331 const string&
term = *t;
333 reply.append(1,
char(reuse));
335 reply.append(
term, reuse, string::npos);
345 const char *
p = message.data();
346 const char *p_end =
p + message.size();
363 const string&
term = *t;
365 reply.append(1,
char(reuse));
367 reply.append(
term, reuse, string::npos);
379 const char *
p = message.data();
380 const char *p_end =
p + message.size();
385 string term(
p, p_end -
p);
402 const char *
p = message.data();
403 const char *p_end =
p + message.size();
413 string term(
p, p_end -
p);
427 const string &
term = message;
440 pack_uint(reply, newdocid - lastdocid - 1);
443 lastdocid = newdocid;
456 const char *
p = msg.c_str();
457 const char *p_end =
p + msg.size();
463 flags = flag_bits &~ Xapian::DB_ACTION_MASK_;
485 static const char protocol[2] = {
489 string message(protocol, 2);
505 const char *
p = message_in.c_str();
506 const char *p_end =
p + message_in.size();
509 string serialisation;
531 if (p_end -
p < 4 ||
static_cast<unsigned char>(*
p) > 2) {
537 if (
static_cast<unsigned char>(*
p) > 3) {
550 bool sort_value_forward;
557 int percent_threshold = *
p++;
558 if (percent_threshold < 0 || percent_threshold > 100) {
563 if (weight_threshold < 0) {
574 if (wttype == NULL) {
579 wtname +
" not registered");
585 unique_ptr<Xapian::Weight> wt(wttype->
unserialise(serialisation));
594 vector<Xapian::Internal::opt_intrusive_ptr<Xapian::MatchSpy>> matchspies;
601 if (spyclass == NULL) {
609 matchspies.push_back(spyclass->
unserialise(serialisation,
615 query, qlen, &rset, local_stats, *wt,
617 collapse_key, collapse_max,
618 percent_threshold, weight_threshold,
619 order, sort_key, sort_by, sort_value_forward, time_limit,
627 p_end =
p + message.size();
639 unique_ptr<Xapian::KeyMaker> sorter;
640 if (!sorter_type.empty()) {
642 if (sorterclass == NULL) {
647 string serialised_sorter;
658 *total_stats, *wt, 0, sorter.get(),
659 collapse_key, collapse_max,
660 percent_threshold, weight_threshold,
662 sort_key, sort_by, sort_value_forward,
663 time_limit, matchspies);
666 mset.
internal->set_stats(total_stats.release());
669 for (
auto i : matchspies) {
672 message += mset.
internal->serialise();
679 const char *
p = message.data();
680 const char *p_end =
p + message.size();
743 const char *
p = message.data();
744 const char *p_end =
p + message.size();
760 const char *
p = message.data();
761 const char *p_end =
p + message.size();
774 const char *
p = message.data();
775 const char *p_end =
p + message.size();
788 const char*
p = message.data();
789 const char* p_end =
p + message.size();
802 const char*
p = message.data();
803 const char* p_end =
p + message.size();
815 start_pos, end_pos));
862 const char *
p = message.data();
863 const char *p_end =
p + message.size();
891 const char *
p = message.data();
892 const char *p_end =
p + message.size();
909 const char *
p = message.data();
910 const char *p_end =
p + message.size();
932 string prev = message;
933 const string& prefix = message;
937 const string&
term = *t;
939 reply.append(1,
char(reuse));
941 reply.append(
term, reuse, string::npos);
952 const char *
p = message.data();
953 const char *p_end =
p + message.size();
958 string val(
p, p_end -
p);
967 const char*
p = message.data();
968 const char* p_end =
p + message.size();
983 const char *
p = message.data();
984 const char *p_end =
p + message.size();
999 const char *
p = message.data();
1000 const char *p_end =
p + message.size();
1016 const string&
term = *t;
1018 reply.append(1,
char(reuse));
1020 reply.append(
term, reuse, string::npos);
1033 const string&
term = *t;
1035 reply.append(1,
char(reuse));
1037 reply.append(
term, reuse, string::npos);
1049 const char*
p = message.data();
1050 const char* p_end =
p + message.size();
1065 const char*
p = message.data();
1066 const char* p_end =
p + message.size();
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())
Xapian::MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount check_at_least, Xapian::Weight::Internal &stats, const Xapian::Weight &wtscheme, const Xapian::MatchDecider *mdecider, const Xapian::KeyMaker *sorter, Xapian::valueno collapse_key, Xapian::doccount collapse_max, int percent_threshold, double weight_threshold, Xapian::Enquire::docid_order order, Xapian::valueno sort_key, Xapian::Enquire::Internal::sort_setting sort_by, bool sort_val_reverse, double time_limit, const std::vector< opt_ptr_spy > &matchspies)
Run the match and produce an MSet object.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
void send_message(char type, std::string_view s, double end_time)
Send a message.
int get_message(std::string &result, double end_time)
Read one message from fdin.
std::string context
The context to report with errors.
Remote backend server base class.
void msg_reconstructtext(const std::string &message)
void msg_adddocument(const std::string &message)
void msg_removespelling(const std::string &message)
void msg_deletedocument(const std::string &message)
double idle_timeout
Timeout while waiting for a new action from the client.
void msg_writeaccess(const std::string &message)
Xapian::Registry reg
The registry, which allows unserialisation of user subclasses.
Xapian::Database * db
The database we're using.
void msg_update(const std::string &message)
void msg_addsynonym(const std::string &message)
void msg_metadatakeylist(const std::string &message)
double active_timeout
Timeout for actions during a conversation.
void msg_setmetadata(const std::string &message)
message_type get_message(double timeout, std::string &result, message_type required_type=MSG_MAX)
Accept a message from the client.
void msg_replacedocument(const std::string &message)
void msg_keepalive(const std::string &message)
void msg_termlist(const std::string &message)
void msg_cancel(const std::string &message)
void msg_addspelling(const std::string &message)
void msg_getmetadata(const std::string &message)
void msg_document(const std::string &message)
void msg_deletedocumentterm(const std::string &message)
void msg_freqs(const std::string &message)
bool writable
Do we support writing?
void msg_wdfdocmax(const std::string &message)
Xapian::WritableDatabase * wdb
The WritableDatabase we're using, or NULL if we're read-only.
void msg_reopen(const std::string &message)
RemoteServer(const RemoteServer &)
Don't allow copying.
void msg_postlist(const std::string &message)
void msg_synonymkeylist(const std::string &message)
void msg_collfreq(const std::string &message)
void msg_termexists(const std::string &message)
void msg_valuestats(const std::string &message)
void msg_doclength(const std::string &message)
void msg_allterms(const std::string &message)
void msg_commit(const std::string &message)
~RemoteServer()
Destructor.
void msg_query(const std::string &message)
void msg_termfreq(const std::string &message)
void msg_positionlist(const std::string &message)
void msg_uniqueterms(const std::string &message)
void msg_synonymtermlist(const std::string &message)
void run()
Repeatedly accept messages from the client and process them.
void msg_positionlistcount(const std::string &message)
void send_message(reply_type type, std::string_view message)
Send a message to the client.
void msg_requestdocument(const std::string &message)
void msg_removesynonym(const std::string &message)
void msg_replacedocumentterm(const std::string &message)
void msg_clearsynonyms(const std::string &message)
An indexed database of documents.
Xapian::TermIterator metadata_keys_begin(std::string_view prefix={}) const
An iterator which returns all user-specified metadata keys.
Xapian::doccount get_termfreq(std::string_view term) const
Get the number of documents indexed by a specified term.
Xapian::TermIterator synonym_keys_begin(std::string_view prefix={}) const
An iterator which returns all terms which have synonyms.
Xapian::totallength get_total_length() const
Get the total length of all the documents in the database.
PositionIterator positionlist_end(Xapian::docid, std::string_view) const noexcept
End iterator corresponding to positionlist_begin().
Xapian::WritableDatabase lock(int flags=0)
Lock a read-only database for writing.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
std::string reconstruct_text(Xapian::docid did, size_t length=0, std::string_view prefix={}, Xapian::termpos start_pos=0, Xapian::termpos end_pos=0) const
Reconstruct document text.
TermIterator termlist_begin(Xapian::docid did) const
Start iterating the terms in a document.
Xapian::termcount get_wdfdocmax(Xapian::docid did) const
Get the maximum wdf value in a specified document.
void keep_alive()
Send a keep-alive message.
PositionIterator positionlist_begin(Xapian::docid did, std::string_view term) const
Start iterating positions for a term in a document.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
Xapian::TermIterator synonyms_end(std::string_view) const noexcept
End iterator corresponding to synonyms_begin(term).
void add_database(const Database &other)
Add shards from another Database.
Xapian::TermIterator synonym_keys_end(std::string_view={}) const noexcept
End iterator corresponding to synonym_keys_begin(prefix).
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a specified document.
Xapian::TermIterator metadata_keys_end(std::string_view={}) const noexcept
End iterator corresponding to metadata_keys_begin().
bool term_exists(std::string_view term) const
Test is a particular term is present in any document.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
TermIterator allterms_end(std::string_view={}) const noexcept
End iterator corresponding to allterms_begin(prefix).
bool has_positions() const
Does this database have any positional information?
Xapian::termcount get_collection_freq(std::string_view term) const
Get the total number of occurrences of a specified term.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
PostingIterator postlist_end(std::string_view) const noexcept
End iterator corresponding to postlist_begin().
TermIterator termlist_end(Xapian::docid) const noexcept
End iterator corresponding to termlist_begin().
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
TermIterator allterms_begin(std::string_view prefix={}) const
Start iterating all terms in the database with a given prefix.
Xapian::TermIterator synonyms_begin(std::string_view term) const
An iterator which returns all the synonyms for a given term.
bool reopen()
Reopen the database at the latest available revision.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
Xapian::Document get_document(Xapian::docid did, unsigned flags=0) const
Get a document from the database.
std::string get_uuid() const
Get the UUID for the database.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
std::string get_metadata(std::string_view key) const
Get the user-specified metadata associated with a given key.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in a specified document.
Class representing a document.
std::string get_data() const
Get the document data.
ValueIterator values_begin() const
Start iterating the values in this document.
ValueIterator values_end() const noexcept
End iterator corresponding to values_begin().
docid_order
Ordering of docids.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
InvalidOperationError indicates the API was used in an invalid way.
Virtual base class for key making functors.
virtual KeyMaker * unserialise(const std::string &serialised, const Registry &context) const
Unserialise parameters.
Class representing a list of search results.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Abstract base class for match spies.
MatchSpy * release()
Start reference counting this object.
virtual MatchSpy * unserialise(const std::string &serialised, const Registry &context) const
Unserialise parameters.
Indicates a problem communicating with a remote database.
Indicates a timeout expired while communicating with a remote database.
Class for iterating over term positions.
Class for iterating over a list of terms.
Class representing a query.
static const Query unserialise(std::string_view serialised, const Registry ®=Registry())
Unserialise a string and return a Query object.
Class representing a set of documents judged as relevant.
const Xapian::MatchSpy * get_match_spy(std::string_view name) const
Get a match spy given a name.
const Xapian::Weight * get_weighting_scheme(std::string_view name) const
Get the weighting scheme given a name.
const Xapian::KeyMaker * get_key_maker(std::string_view name) const
Get a KeyMaker given a name.
virtual Xapian::termcount get_approx_size() const =0
Return approximate size of this termlist.
Class for iterating over a list of terms.
void skip_to(std::string_view term)
Advance the iterator to term term.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Class for iterating over document values.
Xapian::valueno get_valueno() const
Return the value slot number for the current position.
Class to hold statistics for a given collection.
Abstract base class for weighting schemes.
virtual Weight * unserialise(const std::string &serialised) const
Unserialise parameters.
This class provides read/write access to a database.
void delete_document(Xapian::docid did)
Delete a document from the database.
void clear_synonyms(std::string_view term) const
Remove all synonyms for a term.
void begin_transaction(bool flushed=true)
Begin a transaction.
void add_synonym(std::string_view term, std::string_view synonym) const
Add a synonym for a term.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a document in the database.
void set_metadata(std::string_view key, std::string_view metadata)
Set the user-specified metadata associated with a given key.
void cancel_transaction()
Abort the transaction currently in progress.
void add_spelling(std::string_view word, Xapian::termcount freqinc=1) const
Add a word to the spelling dictionary.
termcount remove_spelling(std::string_view word, termcount freqdec=1) const
Remove a word from the spelling dictionary.
void commit()
Commit pending modifications.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
void remove_synonym(std::string_view term, std::string_view synonym) const
Remove a synonym for a term.
#define UNSIGNED_OVERFLOW_OK(X)
Constants in the Xapian namespace.
An indexed database of documents.
Hierarchy of classes which Xapian can throw as exceptions.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
string str(int value)
Convert int to std::string.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
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.
Various assertion macros.
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.
Functions for handling a time or time interval in a double.
#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
static void throw_read_only()
void(RemoteServer::* dispatch_func)(const string &)
Xapian remote backend server base class.
Set of documents judged as relevant.
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
functions to serialise and unserialise a double
string serialise_error(const Xapian::Error &e)
Serialise a Xapian::Error object to a string.
functions to convert classes to strings and back
string serialise_stats(const Xapian::Weight::Internal &stats)
Serialise a stats object.
Xapian::Document unserialise_document(string_view s)
Unserialise a serialised Xapian::Document object.
Xapian::RSet unserialise_rset(const string &s)
Unserialise a serialised Xapian::RSet object.
void unserialise_stats(const char *p, const char *p_end, Xapian::Weight::Internal &stat)
Unserialise a serialised stats object.
functions to convert classes to strings and back
Convert types to std::string.
Various handy string-related helpers.
std::string::size_type common_prefix_length(std::string_view a, std::string_view b)
Class to throw when we receive the connection closing message.
Abstract base class for termlists.
Class for iterating over document values.
Xapian::Weight::Internal class, holding database and term statistics.