Ticket #206: serialise_query_and_document.patch

File serialise_query_and_document.patch, 3.1 KB (added by Richard Boulton, 15 years ago)

Patch implementing this.

  • include/xapian/query.h

     
    238238         */
    239239        bool empty() const;
    240240
     241        /** Serialise query into a string.
     242         *
     243         *  The query representation may change between xapian releases:
     244         *  even between minor versions.  The serialisation should not be used
     245         *  for persistence - it is intended for allowing documents to be
     246         *  passed between clients and servers which are running the same
     247         *  version of xapian.
     248         */
     249        std::string serialise() const;
     250
     251        /** Unserialise a query from a string produced by serialise().
     252         */
     253        static Query unserialise(const std::string &s);
     254
    241255        /// Return a string describing this object.
    242256        std::string get_description() const;
    243257
  • include/xapian/document.h

     
    194194         */
    195195        docid get_docid() const;
    196196
     197        /** Serialise document into a string.
     198         *
     199         *  The document representation may change between xapian releases:
     200         *  even between minor versions.  The serialisation should not be used
     201         *  for persistence - it is intended for allowing documents to be
     202         *  passed between clients and servers which are running the same
     203         *  version of xapian.
     204         */
     205        std::string serialise() const;
     206
     207        /** Unserialise a document from a string produced by serialise().
     208         */
     209        static Document unserialise(const std::string &s);
     210
    197211        /// Return a string describing this object.
    198212        std::string get_description() const;
    199213};
  • api/omdocument.cc

     
    2727#include "document.h"
    2828#include "documentvaluelist.h"
    2929#include "maptermlist.h"
     30#include "serialise.h"
    3031#include "utils.h"
    3132
    3233#include <xapian/error.h>
     
    199200    RETURN(internal->get_docid());
    200201}
    201202
     203std::string
     204Document::serialise() const
     205{
     206    DEBUGAPICALL(std::string, "Document::serialise", "");
     207    return serialise_document(*this);
    202208}
    203209
     210Document
     211Document::unserialise(const std::string &s)
     212{
     213    DEBUGAPICALL_STATIC(Document, "Document::unserialise", s);
     214    return unserialise_document(s);
     215}
     216
     217}
     218
    204219/////////////////////////////////////////////////////////////////////////////
    205220
    206221void
  • api/omquery.cc

     
    194194}
    195195
    196196std::string
     197Query::serialise() const
     198{
     199    DEBUGAPICALL(std::string, "Xapian::Query::serialise", "");
     200    if (!internal.get()) return "";
     201    return internal->serialise();
     202}
     203
     204Query
     205Query::unserialise(const std::string &s)
     206{
     207    DEBUGAPICALL_STATIC(Xapian::Query, "Xapian::Query::unserialise", s);
     208    Query result;
     209    if (!s.empty()) {
     210        result.internal = Xapian::Query::Internal::unserialise(s);
     211    }
     212    RETURN(result);
     213}
     214
     215std::string
    197216Query::get_description() const
    198217{
    199218    std::string res("Xapian::Query(");