# Remote Backend Protocol

This is a brief description of the wire protocol used by the remote backend. This should be up to date for protocol version 16, but hasn't been thoroughly checked yet:

    Message 1:
    Direction: Server->Client
    Format: OM <protocol version> <document count> <average length>
    Description: Identifies protocol version and sends basic statistics.
    When: At connection setting up time.

    Message 2:
    Direction: Client->Server
    Format: Q<query string>\n<options>\n<weighting>\n<R-set>
    Description: The query, options, weighting formula and parameters, and R-set.
    When: At prepare_match() time

    Message 3:
    Direction: Server->Client
    Format: L<serialised local stats>
    Description: The local database statistics

    Message 4:
    Direction: Client->Server
    Format: G<serialised global stats>\nM<first item> <max items>
    Description: The global statistics for all databases are sent,
    	     and the MSet requested.
    When: At get_mset() time.

    Message 5:
    Direction: Server->Client
    Format: O<first> <lower bound> <estimated> <upper bound> <max_possible> <max_attained>\
            <#items> [<weight> <doc id> <collapse key value>]...\
            [<term> <frequency> <weight>]...
    Description: The returned MSet.