61 int fdin_,
int fdout_,
62 double active_timeout_,
double idle_timeout_,
65 db(NULL), wdb(NULL), writable(writable_),
66 active_timeout(active_timeout_), idle_timeout(idle_timeout_)
80 vector<std::string>::const_iterator i(dbpaths.begin());
81 for (++i; i != dbpaths.end(); ++i) {
101 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
130 string errmsg(
"Invalid message type ");
134 if (required_type !=
MSG_MAX && type !=
int(required_type)) {
135 string errmsg(
"Expecting message type ");
136 errmsg +=
str(
int(required_type));
148 unsigned char type_as_char =
static_cast<unsigned char>(type);
205 if (type >=
sizeof(dispatch) /
sizeof(dispatch[0]) || !dispatch[type]) {
206 string errmsg(
"Unexpected message type ");
210 (this->*(dispatch[type]))(message);
248 string prev = message;
251 const string & prefix = message;
254 const string & v = *t;
257 reply.append(1,
char(reuse));
258 reply.append(v, reuse, string::npos);
269 const char *p = message.data();
270 const char *p_end = p + message.size();
278 const string & v = *t;
282 reply.append(1,
char(reuse));
283 reply.append(v, reuse, string::npos);
294 const char *p = message.data();
295 const char *p_end = p + message.size();
298 string term(p, p_end - p);
315 const string & term = message;
331 lastdocid = newdocid;
344 const char *p = msg.c_str();
345 const char *p_end = p + msg.size();
349 flags |= flag_bits &~ Xapian::DB_ACTION_MASK_;
374 static const char protocol[2] = {
378 string message(protocol, 2);
395 const char *p = message_in.c_str();
396 const char *p_end = p + message_in.size();
415 if (p_end - p < 4 || *p < '0' || *p >
'2') {
424 if (*p < '0' || *p >
'3') {
430 if (*p < '0' || *p >
'1') {
433 bool sort_value_forward(*p++ !=
'0');
437 int percent_cutoff = *p++;
438 if (percent_cutoff < 0 || percent_cutoff > 100) {
443 if (weight_cutoff < 0) {
449 string wtname(p, len);
453 if (wttype == NULL) {
458 wtname +
" not registered");
462 AutoPtr<Xapian::Weight> wt(wttype->
unserialise(
string(p, len)));
471 vector<Xapian::Internal::opt_intrusive_ptr<Xapian::MatchSpy>> matchspies;
474 string spytype(p, len);
476 if (spyclass == NULL) {
488 MultiMatch match(*
db, query, qlen, &rset, collapse_max, collapse_key,
489 percent_cutoff, weight_cutoff, order,
490 sort_key, sort_by, sort_value_forward, time_limit,
491 local_stats, wt.get(), matchspies,
false,
false);
498 p_end = p + message.size();
510 total_stats->set_bounds_from_db(*
db);
513 match.get_mset(first, maxitems, check_at_least, mset, *(total_stats.get()), 0, 0);
514 mset.
internal->stats = total_stats.release();
517 for (
auto i : matchspies) {
518 string spy_results = i->serialise_results();
520 message += spy_results;
529 const char *p = message.data();
530 const char *p_end = p + message.size();
584 const char *p = message.data();
585 const char *p_end = p + message.size();
593 message_out += bound;
596 message_out += bound;
605 const char *p = message.data();
606 const char *p_end = p + message.size();
615 const char *p = message.data();
616 const char *p_end = p + message.size();
669 const char *p = message.data();
670 const char *p_end = p + message.size();
708 const char *p = message.data();
709 const char *p_end = p + message.size();
722 const char *p = message.data();
723 const char *p_end = p + message.size();
726 string unique_term(p, len);
743 string prev = message;
746 const string & prefix = message;
749 for (; t != end; ++t) {
750 const string & v = *t;
752 reply.assign(1,
char(reuse));
753 reply.append(v, reuse, string::npos);
772 const char *p = message.data();
773 const char *p_end = p + message.size();
776 string key(p, keylen);
778 string val(p, p_end - p);
794 const char *p = message.data();
795 const char *p_end = p + message.size();
806 const char *p = message.data();
807 const char *p_end = p + message.size();
Xapian::Document get_document(Xapian::docid did) const
Get a document from the database, given its document id.
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
static void throw_read_only()
Define the XAPIAN_NORETURN macro.
PositionIterator positionlist_end(Xapian::docid, const std::string &) const
Corresponding end iterator to positionlist_begin().
~RemoteServer()
Destructor.
static const Query unserialise(const std::string &serialised, const Registry ®=Registry())
Unserialise a string and return a Query object.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
void msg_cancel_(const std::string &message)
void msg_positionlist(const std::string &message)
TermIterator termlist_begin(Xapian::docid did) const
An iterator pointing to the start of the termlist for a given document.
Xapian::RSet unserialise_rset(const string &s)
Unserialise a serialised Xapian::RSet object.
void cancel_transaction()
Abort the transaction currently in progress, discarding the pending modifications made to the databas...
length encoded as a string
int get_message(std::string &result, double end_time)
Read one message from fdin.
This class is used to access a database, or a group of databases.
unsigned timeout
A timeout value in milliseconds.
class for performing a match
Xapian::WritableDatabase * wdb
The WritableDatabase we're using, or NULL if we're read-only.
void msg_keepalive(const std::string &message)
void msg_cancel(const std::string &message)
void remove_spelling(const std::string &word, Xapian::termcount freqdec=1) const
Remove a word from the spelling dictionary.
MatchSpy * release()
Start reference counting this object.
InvalidOperationError indicates the API was used in an invalid way.
Xapian::Document unserialise_document(const string &s)
Unserialise a serialised Xapian::Document object.
PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const
An iterator pointing to the start of the position list for a given term in a given document...
void msg_reopen(const std::string &message)
Abstract base class for match spies.
void msg_collfreq(const std::string &message)
RemoteServer(const RemoteServer &)
Don't allow copying.
Indicates a timeout expired while communicating with a remote database.
Xapian::termcount get_doclength_lower_bound() const
Get a lower bound on the length of a document in this DB.
bool has_positions() const
Does this database have any positional information?
ValueIterator values_begin() const
Iterator for the values in this document.
void send_message(reply_type type, const std::string &message)
Send a message to the client.
TermIterator allterms_end(const std::string &=std::string()) const
Corresponding end iterator to allterms_begin(prefix).
Xapian::Internal::intrusive_ptr< Internal > internal
Constants in the Xapian namespace.
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
void msg_openmetadatakeylist(const std::string &message)
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
void msg_replacedocumentterm(const std::string &message)
Xapian::Registry reg
The registry, which allows unserialisation of user subclasses.
void begin_transaction(bool flushed=true)
Begin a transaction.
bool reopen()
Re-open the database.
reply_type
Reply types (server -> client).
Class for iterating over document values.
Class representing a list of search results.
Convert types to std::string.
void msg_uniqueterms(const std::string &message)
void msg_termlist(const std::string &message)
string serialise_error(const Xapian::Error &e)
Serialise a Xapian::Error object to a string.
double active_timeout
Timeout for actions during a conversation.
void msg_replacedocument(const std::string &message)
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
void set_metadata(const std::string &key, const std::string &metadata)
Set the user-specified metadata associated with a given key.
std::string encode_length(T len)
Encode a length as a variable-length string.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
std::string get_metadata(const std::string &key) const
Get the user-specified metadata associated with a given key.
Class to throw when we receive the connection closing message.
Xapian::totallength get_total_length() const
Get the total length of all the documents in the database.
void msg_replacedocument_(const std::string &message)
void msg_adddocument(const std::string &message)
void msg_setmetadata(const std::string &message)
std::string context
The context to report with errors.
void msg_removespelling(const std::string &message)
bool writable
Do we support writing?
Hierarchy of classes which Xapian can throw as exceptions.
Class for iterating over a list of terms.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Class for iterating over a list of terms.
functions to serialise and unserialise a double
const Xapian::MatchSpy * get_match_spy(const std::string &name) const
Get a match spy given a name.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Xapian::termcount get_doclength_upper_bound() const
Get an upper bound on the length of a document in this DB.
void run()
Repeatedly accept messages from the client and process them.
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
void msg_deletedocumentterm(const std::string &message)
void msg_addspelling_(const std::string &message)
const int DB_OPEN
Open an existing database.
This class provides read/write access to a database.
Xapian::Weight::Internal class, holding database and term statistics.
void msg_postlist(const std::string &message)
void msg_commit(const std::string &message)
Class to hold statistics for a given collection.
const Xapian::Weight * get_weighting_scheme(const std::string &name) const
Get the weighting scheme given a name.
void delete_document(Xapian::docid did)
Delete a document from the database.
API for working with Xapian databases.
string str(int value)
Convert int to std::string.
void(RemoteServer::* dispatch_func)(const string &)
Xapian::termcount get_doclength(Xapian::docid did) const
Get the length of a document.
Class for iterating over document values.
void commit()
Commit any pending modifications made to the database.
Xapian remote backend server base class.
void msg_getmetadata(const std::string &message)
Class for iterating over term positions.
double idle_timeout
Timeout while waiting for a new action from the client.
void msg_addspelling(const std::string &message)
void msg_setmetadata_(const std::string &message)
#define XAPIAN_REMOTE_PROTOCOL_MAJOR_VERSION
ValueIterator values_end() const
Equivalent end iterator for values_begin().
string serialise_stats(const Xapian::Weight::Internal &stats)
Serialise a stats object.
TermIterator allterms_begin(const std::string &prefix=std::string()) const
An iterator which runs across all terms with a given prefix.
TermIterator termlist_end(Xapian::docid) const
Corresponding end iterator to termlist_begin().
void msg_valuestats(const std::string &message)
functions to convert classes to strings and back
bool term_exists(const std::string &tname) const
Check if a given term exists in the database.
void msg_allterms(const std::string &message)
void msg_doclength(const std::string &message)
#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())
void msg_query(const std::string &message)
void unserialise_stats(const char *p, const char *p_end, Xapian::Weight::Internal &stat)
Unserialise a serialised stats object.
void decode_length_and_check(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
string serialise_mset(const Xapian::MSet &mset)
Serialise a Xapian::MSet object.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Xapian::Database * db
The database we're using.
void msg_writeaccess(const std::string &message)
All exceptions thrown by Xapian are subclasses of Xapian::Error.
Indicates a problem communicating with a remote database.
std::string get_value_lower_bound(Xapian::valueno slot) const
Get a lower bound on the values stored in the given value slot.
std::string::size_type common_prefix_length(const std::string &a, const std::string &b)
unsigned valueno
The number for a value slot in a document.
void msg_deletedocument(const std::string &message)
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various handy helpers which std::string really should provide.
void msg_termexists(const std::string &message)
message_type
Message types (client -> server).
void send_message(char type, const std::string &s, double end_time)
Send a message.
Xapian::TermIterator metadata_keys_begin(const std::string &prefix=std::string()) const
An iterator which returns all user-specified metadata keys.
void msg_update(const std::string &message)
void keep_alive()
Send a "keep-alive" to remote databases to stop them timing out.
virtual Weight * unserialise(const std::string &serialised) const
Unserialise parameters.
Remote backend server base class.
void msg_freqs(const std::string &message)
Various assertion macros.
Functions for handling a time or time interval in a double.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Class representing a query.
std::string get_data() const
Get data stored in the document.
virtual MatchSpy * unserialise(const std::string &serialised, const Registry &context) const
Unserialise parameters.
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
void msg_deletedocumentterm_(const std::string &message)
void msg_document(const std::string &message)
Xapian::termcount get_unique_terms(Xapian::docid did) const
Get the number of unique terms in document.
PostingIterator postlist_end(const std::string &) const
Corresponding end iterator to postlist_begin().
functions to convert classes to strings and back
docid_order
Ordering of docids.
void decode_length(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
Xapian::doccount get_termfreq(const std::string &tname) const
Get the number of documents in the database indexed by a given term.
Xapian::doccount get_value_freq(Xapian::valueno slot) const
Return the frequency of a given value slot.
A handle representing a document in a Xapian database.
Wrapper around standard unique_ptr template.
void msg_termfreq(const std::string &message)
std::string get_uuid() const
Get a UUID for the database.
void add_spelling(const std::string &word, Xapian::termcount freqinc=1) const
Add a word to the spelling dictionary.
PostingIterator postlist_begin(const std::string &tname) const
An iterator pointing to the start of the postlist for a given term.
message_type get_message(double timeout, std::string &result, message_type required_type=MSG_MAX)
Accept a message from the client.
Abstract base class for weighting schemes.
Xapian::termcount get_collection_freq(const std::string &tname) const
Return the total number of occurrences of the given term.
Xapian::TermIterator metadata_keys_end(const std::string &=std::string()) const
Corresponding end iterator to metadata_keys_begin().