RemoteDatabase Class Reference

RemoteDatabase is the baseclass for remote database implementations. More...

#include <remote-database.h>

Inheritance diagram for RemoteDatabase:

Inheritance graph
[legend]
Collaboration diagram for RemoteDatabase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

RemoteDatabaseas_remotedatabase ()
 Return this pointer as a RemoteDatabase*.
void keep_alive ()
 Send a keep-alive message.
void set_query (const Xapian::Query::Internal *query, Xapian::termcount qlen, Xapian::valueno collapse_key, Xapian::Enquire::docid_order order, Xapian::valueno sort_key, Xapian::Enquire::Internal::sort_setting sort_by, bool sort_value_forward, int percent_cutoff, Xapian::weight weight_cutoff, const Xapian::Weight *wtscheme, const Xapian::RSet &omrset)
 Set the query.
bool get_remote_stats (bool nowait, Stats &out)
 Get the Stats from the remote server.
void send_global_stats (Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount check_at_least, const Stats &stats)
 Send the global Stats to the remote server.
void get_mset (Xapian::MSet &mset)
 Get the MSet from the remote server.
TermListopen_term_list (Xapian::docid did) const
 Get remote termlist.
TermListopen_allterms (const string &prefix) const
 Iterate all terms.
bool has_positions () const
 Check whether this database contains any positional information.
void reopen ()
 Reopen the database to the latest available revision.
LeafPostListopen_post_list (const string &tname) const
 Open a posting list.
Xapian::doccount read_post_list (const string &term, NetworkPostList &pl) const
PositionListopen_position_list (Xapian::docid did, const string &tname) const
 Open a position list for the given term in the given document.
Xapian::Document::Internalopen_document (Xapian::docid did, bool lazy) const
 Get a remote document.
Xapian::doccount get_doccount () const
 Get the document count.
Xapian::docid get_lastdocid () const
 Get the last used docid.
Xapian::doclength get_avlength () const
 Find out the remote average document length.
Xapian::doclength get_doclength (Xapian::docid did) const
 Get the length of a given document.
bool term_exists (const string &tname) const
 Check if term exists.
Xapian::doccount get_termfreq (const string &tname) const
 Find frequency of term.
Xapian::termcount get_collection_freq (const string &tname) const
 Return the total number of occurrences of the given term.
void flush ()
 Flush pending modifications to the database.
void cancel ()
 Cancel pending modifications to the database.
Xapian::docid add_document (const Xapian::Document &doc)
 Add a new document to the database.
void delete_document (Xapian::docid did)
 Delete a document in the database.
void delete_document (const std::string &unique_term)
void replace_document (Xapian::docid did, const Xapian::Document &doc)
 Replace a given document in the database.
Xapian::docid replace_document (const std::string &unique_term, const Xapian::Document &document)

Protected Member Functions

 RemoteDatabase (int fd, Xapian::timeout timeout_, const string &context_, bool writable)
 Constructor.
reply_type get_message (string &message, reply_type required_type=REPLY_MAX) const
 Receive a message from the server.
void send_message (message_type type, const string &data) const
 Send a message to the server.
void do_close ()
 Close the socket.
bool get_posting (Xapian::docid &did, Xapian::weight &w, string &value)

Protected Attributes

Xapian::timeout timeout
 The timeout value used in network communications, in milliseconds.

Private Member Functions

void operator= (const RemoteDatabase &)
 Don't allow assignment.
 RemoteDatabase (const RemoteDatabase &)
 Don't allow copying.
void update_stats (message_type msg_code=MSG_UPDATE) const

Private Attributes

RemoteConnection link
 The object which does the I/O.
Xapian::doccount doccount
 The remote document count, given at open.
Xapian::docid lastdocid
 The remote last docid, given at open.
Xapian::doclength avlength
 The remote document avlength, given at open.
bool has_positional_info
 Has positional information?
string context
 The context to return with any error messages.
bool cached_stats_valid

Detailed Description

RemoteDatabase is the baseclass for remote database implementations.

A subclass of this class is required which opens a TCP connection or pipe to the remote database server. This subclass works in combination with the RemoteSubMatch class during the match process.

Definition at line 45 of file remote-database.h.


Constructor & Destructor Documentation

RemoteDatabase::RemoteDatabase ( const RemoteDatabase  )  [private]

Don't allow copying.

RemoteDatabase::RemoteDatabase ( int  fd,
Xapian::timeout  timeout_,
const string &  context_,
bool  writable 
) [protected]

Constructor.

The constructor is protected so that raw instances can't be created - a derived class must be instantiated which has code in the constructor to open the socket.

Parameters:
fd The file descriptor for the connection to the server.
timeout_ The timeout used with the network operations. Generally a Xapian::NetworkTimeoutError exception will be thrown if the remote end doesn't respond for this length of time (in milliseconds). A timeout of 0 means that operations will never timeout.
context_ The context to return with any error messages.
writable Is this a WritableDatabase?

Definition at line 47 of file remote-database.cc.

References avlength, context, decode_length(), doccount, get_message(), has_positional_info, lastdocid, om_tostring(), REPLY_GREETING, STRINGIZE, Xapian::Database::Internal::transaction_state, Xapian::Database::Internal::TRANSACTION_UNIMPLEMENTED, unserialise_double(), XAPIAN_REMOTE_PROTOCOL_MAJOR_VERSION, and XAPIAN_REMOTE_PROTOCOL_MINOR_VERSION.


Member Function Documentation

void RemoteDatabase::operator= ( const RemoteDatabase  )  [private]

Don't allow assignment.

void RemoteDatabase::update_stats ( message_type  msg_code = MSG_UPDATE  )  const [private]

Definition at line 298 of file remote-database.cc.

References avlength, cached_stats_valid, context, decode_length(), doccount, get_message(), has_positional_info, lastdocid, REPLY_UPDATE, send_message(), and unserialise_double().

Referenced by get_avlength(), get_doccount(), get_lastdocid(), has_positions(), open_allterms(), open_term_list(), and reopen().

reply_type RemoteDatabase::get_message ( string &  message,
reply_type  required_type = REPLY_MAX 
) const [protected]

Receive a message from the server.

Definition at line 393 of file remote-database.cc.

References context, RemoteConnection::get_message(), link, OmTime::now(), om_tostring(), REPLY_EXCEPTION, REPLY_MAX, timeout, and unserialise_error().

Referenced by add_document(), delete_document(), flush(), get_collection_freq(), get_doclength(), get_mset(), get_remote_stats(), get_termfreq(), keep_alive(), open_allterms(), open_document(), open_position_list(), open_term_list(), read_post_list(), RemoteDatabase(), replace_document(), term_exists(), and update_stats().

void RemoteDatabase::send_message ( message_type  type,
const string &  data 
) const [protected]

Send a message to the server.

Definition at line 414 of file remote-database.cc.

References link, OmTime::now(), RemoteConnection::send_message(), and timeout.

Referenced by add_document(), cancel(), delete_document(), flush(), get_collection_freq(), get_doclength(), get_termfreq(), keep_alive(), open_allterms(), open_document(), open_position_list(), open_term_list(), read_post_list(), replace_document(), send_global_stats(), set_query(), term_exists(), and update_stats().

void RemoteDatabase::do_close (  )  [protected]

Close the socket.

Definition at line 423 of file remote-database.cc.

References RemoteConnection::do_close(), Xapian::Database::Internal::dtor_called(), link, Xapian::Database::Internal::transaction_state, and Xapian::Database::Internal::TRANSACTION_UNIMPLEMENTED.

Referenced by ProgClient::~ProgClient().

bool RemoteDatabase::get_posting ( Xapian::docid did,
Xapian::weight w,
string &  value 
) [protected]

RemoteDatabase * RemoteDatabase::as_remotedatabase (  )  [virtual]

Return this pointer as a RemoteDatabase*.

Reimplemented from Xapian::Database::Internal.

Definition at line 114 of file remote-database.cc.

void RemoteDatabase::keep_alive (  )  [virtual]

Send a keep-alive message.

Reimplemented from Xapian::Database::Internal.

Definition at line 120 of file remote-database.cc.

References get_message(), MSG_KEEPALIVE, REPLY_DONE, and send_message().

void RemoteDatabase::set_query ( const Xapian::Query::Internal query,
Xapian::termcount  qlen,
Xapian::valueno  collapse_key,
Xapian::Enquire::docid_order  order,
Xapian::valueno  sort_key,
Xapian::Enquire::Internal::sort_setting  sort_by,
bool  sort_value_forward,
int  percent_cutoff,
Xapian::weight  weight_cutoff,
const Xapian::Weight wtscheme,
const Xapian::RSet omrset 
)

Set the query.

Parameters:
query The query.
qlen The query length.
collapse_key The value number to collapse matches on.
order Sort order for docids.
sort_key The value number to sort on.
sort_by Which order to apply sorts in.
sort_value_forward Sort order for values.
percent_cutoff Percentage cutoff.
weight_cutoff Weight cutoff.
wtscheme Weighting scheme.
omrset The rset.

Definition at line 441 of file remote-database.cc.

References encode_length(), MSG_QUERY, Xapian::Weight::name(), query(), send_message(), Xapian::Weight::serialise(), serialise_double(), and serialise_rset().

Referenced by MultiMatch::MultiMatch().

bool RemoteDatabase::get_remote_stats ( bool  nowait,
Stats out 
)

Get the Stats from the remote server.

Returns:
true if we got the remote stats; false if we should try again.

Definition at line 480 of file remote-database.cc.

References get_message(), link, RemoteConnection::ready_to_read(), REPLY_STATS, and unserialise_stats().

Referenced by RemoteSubMatch::prepare_match().

void RemoteDatabase::send_global_stats ( Xapian::doccount  first,
Xapian::doccount  maxitems,
Xapian::doccount  check_at_least,
const Stats stats 
)

Send the global Stats to the remote server.

Definition at line 492 of file remote-database.cc.

References encode_length(), MSG_GETMSET, send_message(), and serialise_stats().

Referenced by RemoteSubMatch::start_match().

void RemoteDatabase::get_mset ( Xapian::MSet mset  ) 

Get the MSet from the remote server.

Definition at line 505 of file remote-database.cc.

References get_message(), REPLY_RESULTS, and unserialise_mset().

Referenced by RemoteSubMatch::get_mset(), and RemoteSubMatch::get_postlist_and_term_info().

TermList * RemoteDatabase::open_term_list ( Xapian::docid  did  )  const [virtual]

Get remote termlist.

Implements Xapian::Database::Internal.

Definition at line 128 of file remote-database.cc.

References cached_stats_valid, context, decode_length(), doccount, encode_length(), get_message(), MSG_TERMLIST, AutoPtr< _Tp >::release(), REPLY_DOCLENGTH, REPLY_DONE, REPLY_TERMLIST, send_message(), NetworkTermListItem::termfreq, NetworkTermListItem::tname, unserialise_double(), update_stats(), and NetworkTermListItem::wdf.

TermList * RemoteDatabase::open_allterms ( const string &  prefix  )  const [virtual]

Iterate all terms.

Implements Xapian::Database::Internal.

Definition at line 171 of file remote-database.cc.

References cached_stats_valid, context, decode_length(), doccount, get_message(), MSG_ALLTERMS, AutoPtr< _Tp >::release(), REPLY_ALLTERMS, REPLY_DONE, send_message(), NetworkTermListItem::termfreq, NetworkTermListItem::tname, and update_stats().

bool RemoteDatabase::has_positions (  )  const [virtual]

Check whether this database contains any positional information.

Implements Xapian::Database::Internal.

Definition at line 254 of file remote-database.cc.

References cached_stats_valid, has_positional_info, and update_stats().

void RemoteDatabase::reopen (  )  [virtual]

Reopen the database to the latest available revision.

Database backends which don't support simultaneous update and reading probably don't need to do anything here.

Reimplemented from Xapian::Database::Internal.

Definition at line 261 of file remote-database.cc.

References MSG_REOPEN, and update_stats().

LeafPostList * RemoteDatabase::open_post_list ( const string &  tname  )  const [virtual]

Open a posting list.

Method defined by subclass to open a posting list. This is a list of all the documents which contain a given term.

Parameters:
tname The term whose posting list is being requested.
Returns:
A pointer to the newly created posting list. If the term doesn't exist, a new EmptyPostList object (or an object which behaves the same way) is returned instead, which makes it easier to implement a search over multiple databases. This object must be deleted by the caller after use.

Implements Xapian::Database::Internal.

Definition at line 202 of file remote-database.cc.

Xapian::doccount RemoteDatabase::read_post_list ( const string &  term,
NetworkPostList pl 
) const

Definition at line 208 of file remote-database.cc.

References NetworkPostList::append_posting(), context, decode_length(), get_message(), MSG_POSTLIST, REPLY_DONE, REPLY_POSTLISTITEM, REPLY_POSTLISTSTART, and send_message().

PositionList * RemoteDatabase::open_position_list ( Xapian::docid  did,
const string &  tname 
) const [virtual]

Open a position list for the given term in the given document.

Parameters:
did The document id for which a position list is being requested.
tname The term for which a position list is being requested.
Returns:
A pointer to the newly created position list. This object must be deleted by the caller after use.

Implements Xapian::Database::Internal.

Definition at line 231 of file remote-database.cc.

References context, decode_length(), encode_length(), get_message(), MSG_POSITIONLIST, REPLY_DONE, REPLY_POSITIONLIST, and send_message().

Xapian::Document::Internal * RemoteDatabase::open_document ( Xapian::docid  did,
bool  lazy 
) const [virtual]

Get a remote document.

Implements Xapian::Database::Internal.

Definition at line 273 of file remote-database.cc.

References context, decode_length(), encode_length(), get_message(), MSG_DOCUMENT, REPLY_DOCDATA, REPLY_DONE, REPLY_VALUE, and send_message().

Xapian::doccount RemoteDatabase::get_doccount (  )  const [virtual]

Get the document count.

Implements Xapian::Database::Internal.

Definition at line 319 of file remote-database.cc.

References cached_stats_valid, doccount, and update_stats().

Xapian::docid RemoteDatabase::get_lastdocid (  )  const [virtual]

Get the last used docid.

Implements Xapian::Database::Internal.

Definition at line 326 of file remote-database.cc.

References cached_stats_valid, lastdocid, and update_stats().

Xapian::doclength RemoteDatabase::get_avlength (  )  const [virtual]

Find out the remote average document length.

Implements Xapian::Database::Internal.

Definition at line 333 of file remote-database.cc.

References avlength, cached_stats_valid, and update_stats().

Xapian::doclength RemoteDatabase::get_doclength ( Xapian::docid  did  )  const [virtual]

Get the length of a given document.

Document length, for the purposes of Xapian, is defined to be the number of instances of terms within a document. Expressed differently, the sum of the within document frequencies over all the terms in the document.

Parameters:
did The document id of the document whose length is being requested.

Implements Xapian::Database::Internal.

Definition at line 377 of file remote-database.cc.

References Assert, context, encode_length(), get_message(), MSG_DOCLENGTH, REPLY_DOCLENGTH, send_message(), and unserialise_double().

bool RemoteDatabase::term_exists ( const string &  tname  )  const [virtual]

Check if term exists.

Implements Xapian::Database::Internal.

Definition at line 340 of file remote-database.cc.

References Assert, context, get_message(), MSG_TERMEXISTS, REPLY_TERMDOESNTEXIST, REPLY_TERMEXISTS, and send_message().

Xapian::doccount RemoteDatabase::get_termfreq ( const string &  tname  )  const [virtual]

Find frequency of term.

Implements Xapian::Database::Internal.

Definition at line 353 of file remote-database.cc.

References Assert, decode_length(), get_message(), MSG_TERMFREQ, REPLY_TERMFREQ, and send_message().

Xapian::termcount RemoteDatabase::get_collection_freq ( const string &  tname  )  const [virtual]

Return the total number of occurrences of the given term.

This is the sum of the number of ocurrences of the term in each document: ie, the sum of the within document frequencies of the term.

Parameters:
tname The term whose collection frequency is being requested.

Implements Xapian::Database::Internal.

Definition at line 365 of file remote-database.cc.

References Assert, decode_length(), get_message(), MSG_COLLFREQ, REPLY_COLLFREQ, and send_message().

void RemoteDatabase::flush (  )  [virtual]

Flush pending modifications to the database.

See WritableDatabase::flush() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 513 of file remote-database.cc.

References get_message(), MSG_FLUSH, REPLY_DONE, and send_message().

void RemoteDatabase::cancel (  )  [virtual]

Cancel pending modifications to the database.

Reimplemented from Xapian::Database::Internal.

Definition at line 523 of file remote-database.cc.

References cached_stats_valid, MSG_CANCEL, and send_message().

Xapian::docid RemoteDatabase::add_document ( const Xapian::Document document  )  [virtual]

Add a new document to the database.

See WritableDatabase::add_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 531 of file remote-database.cc.

References cached_stats_valid, decode_length(), get_message(), MSG_ADDDOCUMENT, REPLY_ADDDOCUMENT, send_message(), and serialise_document().

void RemoteDatabase::delete_document ( Xapian::docid  did  )  [virtual]

Delete a document in the database.

See WritableDatabase::delete_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 546 of file remote-database.cc.

References cached_stats_valid, dummy, encode_length(), get_message(), MSG_DELETEDOCUMENT, REPLY_DONE, and send_message().

void RemoteDatabase::delete_document ( const std::string &  unique_term  ) 

Definition at line 557 of file remote-database.cc.

References cached_stats_valid, MSG_DELETEDOCUMENTTERM, and send_message().

void RemoteDatabase::replace_document ( Xapian::docid  did,
const Xapian::Document document 
) [virtual]

Replace a given document in the database.

See WritableDatabase::replace_document() for more information.

Reimplemented from Xapian::Database::Internal.

Definition at line 565 of file remote-database.cc.

References cached_stats_valid, encode_length(), MSG_REPLACEDOCUMENT, send_message(), and serialise_document().

Xapian::docid RemoteDatabase::replace_document ( const std::string &  unique_term,
const Xapian::Document document 
)

Definition at line 577 of file remote-database.cc.

References cached_stats_valid, decode_length(), encode_length(), get_message(), MSG_REPLACEDOCUMENTTERM, REPLY_ADDDOCUMENT, send_message(), and serialise_document().


Member Data Documentation

RemoteConnection RemoteDatabase::link [mutable, private]

The object which does the I/O.

Definition at line 53 of file remote-database.h.

Referenced by do_close(), get_message(), get_remote_stats(), and send_message().

Xapian::doccount RemoteDatabase::doccount [mutable, private]

The remote document count, given at open.

Definition at line 56 of file remote-database.h.

Referenced by get_doccount(), open_allterms(), open_term_list(), RemoteDatabase(), and update_stats().

Xapian::docid RemoteDatabase::lastdocid [mutable, private]

The remote last docid, given at open.

Definition at line 59 of file remote-database.h.

Referenced by get_lastdocid(), RemoteDatabase(), and update_stats().

Xapian::doclength RemoteDatabase::avlength [mutable, private]

The remote document avlength, given at open.

Definition at line 62 of file remote-database.h.

Referenced by get_avlength(), RemoteDatabase(), and update_stats().

bool RemoteDatabase::has_positional_info [mutable, private]

Has positional information?

Definition at line 65 of file remote-database.h.

Referenced by has_positions(), RemoteDatabase(), and update_stats().

string RemoteDatabase::context [private]

The context to return with any error messages.

Definition at line 68 of file remote-database.h.

Referenced by get_doclength(), get_message(), open_allterms(), open_document(), open_position_list(), open_term_list(), read_post_list(), RemoteDatabase(), term_exists(), and update_stats().

bool RemoteDatabase::cached_stats_valid [mutable, private]

Definition at line 70 of file remote-database.h.

Referenced by add_document(), cancel(), delete_document(), get_avlength(), get_doccount(), get_lastdocid(), has_positions(), open_allterms(), open_term_list(), replace_document(), and update_stats().

Xapian::timeout RemoteDatabase::timeout [protected]

The timeout value used in network communications, in milliseconds.

Definition at line 103 of file remote-database.h.

Referenced by get_message(), and send_message().


The documentation for this class was generated from the following files:
Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.