Ticket #178: metadata_and_mvcms_register.patch

File metadata_and_mvcms_register.patch, 5.7 KB (added by Paul Rudin, 15 years ago)
  • xapian-core/tests/api_metadata.cc

     
    122122}
    123123
    124124// Test metadata iterators.
    125 DEFINE_TESTCASE(metadata5, writable) {
     125DEFINE_TESTCASE(metadata5, writable && !remote) {
    126126    Xapian::WritableDatabase db = get_writable_database();
    127127
    128128    // Check that iterator on empty database returns nothing.
  • xapian-core/tests/harness/testrunner.cc

     
    5858               "synonyms,replicas,flint" },
    5959    { "multi_flint", "backend,positional,multi" },
    6060    { "multi_chert", "backend,positional,valuestats,multi" },
    61     { "remoteprog_flint", "backend,remote,transactions,positional,writable" },
    62     { "remotetcp_flint", "backend,remote,transactions,positional,writable" },
    63     { "remoteprog_chert", "backend,remote,transactions,positional,valuestats,writable" },
    64     { "remotetcp_chert", "backend,remote,transactions,positional,valuestats,writable" },
     61    { "remoteprog_flint", "backend,remote,transactions,positional,writable,metadata" },
     62    { "remotetcp_flint", "backend,remote,transactions,positional,writable,metadata" },
     63    { "remoteprog_chert", "backend,remote,transactions,positional,valuestats,writable,metadata" },
     64    { "remotetcp_chert", "backend,remote,transactions,positional,valuestats,writable,metadata" },
    6565    { NULL, NULL }
    6666};
    6767
  • xapian-core/net/remoteserver.cc

     
    185185                &RemoteServer::msg_replacedocumentterm,
    186186                &RemoteServer::msg_deletedocument,
    187187                &RemoteServer::msg_writeaccess,
     188                &RemoteServer::msg_getmetadata,
     189                &RemoteServer::msg_setmetadata,
    188190                // MSG_GETMSET - used during a conversation.
    189191                // MSG_SHUTDOWN - handled by get_message().
    190192            };
     
    658660
    659661    send_message(REPLY_ADDDOCUMENT, encode_length(did));
    660662}
     663
     664
     665void
     666RemoteServer::msg_getmetadata(const string & message)
     667{
     668  send_message(REPLY_METADATA, db->get_metadata(message));
     669}
     670
     671void
     672RemoteServer::msg_setmetadata(const string & message)
     673{               
     674  if (!wdb)
     675    throw Xapian::InvalidOperationError("Server is read-only");
     676  const char *p = message.data();
     677  const char *p_end = p + message.size();
     678  size_t keylen = decode_length(&p, p_end, false);
     679  string key = string(p, keylen);
     680  p += keylen;
     681  string val = string(p);
     682  wdb->set_metadata(key, val);
     683}
  • xapian-core/common/remote-database.h

     
    241241                                   const Xapian::Document & document);
    242242
    243243    std::string get_uuid() const;
     244
     245    string get_metadata(const string & key) const;
     246
     247    void set_metadata(const string & key, const string & value);
    244248};
    245249
    246250#endif // XAPIAN_INCLUDED_REMOTE_DATABASE_H
  • xapian-core/common/remoteprotocol.h

     
    7373    MSG_REPLACEDOCUMENTTERM,    // Replace Document by term
    7474    MSG_DELETEDOCUMENT,         // Delete Document
    7575    MSG_WRITEACCESS,            // Upgrade to WritableDatabase
     76    MSG_GETMETADATA,            // get metadata
     77    MSG_SETMETADATA,            // set metadata
    7678    MSG_GETMSET,                // Get MSet
    7779    MSG_SHUTDOWN,               // Shutdown
    7880    MSG_MAX
     
    100102    REPLY_VALUE,                // Document Value
    101103    REPLY_ADDDOCUMENT,          // Add Document
    102104    REPLY_RESULTS,              // Results (MSet)
     105    REPLY_METADATA,             // Metadata
    103106    REPLY_MAX
    104107};
    105108
  • xapian-core/common/remoteserver.h

     
    142142    // replace document with unique term
    143143    void msg_replacedocumentterm(const std::string & message);
    144144
     145    // get metadata
     146    void msg_getmetadata(const std::string & message);
     147
     148    // set metadata
     149    void msg_setmetadata(const std::string & message);
     150
     151
    145152  public:
    146153    /** Construct a RemoteServer.
    147154     *
  • xapian-core/api/registry.cc

     
    194194    Xapian::MatchSpy * spy;
    195195    spy = new Xapian::ValueCountMatchSpy();
    196196    matchspies[spy->name()] = spy;
     197
     198    Xapian::MatchSpy * mvspy;
     199    mvspy = new Xapian::MultiValueCountMatchSpy();
     200    matchspies[mvspy->name()] = mvspy;
    197201}
    198202
    199203void
  • xapian-core/backends/remote/remote-database.cc

     
    723723{
    724724    return uuid;
    725725}
     726
     727
     728string
     729RemoteDatabase::get_metadata(const string & key) const
     730{
     731  send_message(MSG_GETMETADATA, key);
     732  string metadata;
     733  get_message(metadata, REPLY_METADATA);
     734  return metadata;
     735}
     736
     737void
     738RemoteDatabase::set_metadata(const string & key, const string & value)
     739{
     740  string data = encode_length(key.size());
     741  data += key;
     742  data += value;
     743  send_message(MSG_SETMETADATA, data);
     744}