Ticket #206: serialisationcontext.patch

File serialisationcontext.patch, 27.0 KB (added by Richard Boulton, 15 years ago)

Patch to allow serialisation of queries containing posting sources

  • xapian-core/tests/internaltest.cc

     
    452452        Xapian::Query::Internal * qint;
    453453
    454454        s = query->internal->serialise();
    455         map<string, Xapian::PostingSource *> m;
    456         qint = Xapian::Query::Internal::unserialise(s, m);
     455        Xapian::SerialisationContext ctx;
     456        qint = Xapian::Query::Internal::unserialise(s, ctx);
    457457
    458458        TEST(qint->serialise() == s);
    459459        delete qint;
  • xapian-core/include/xapian/query.h

     
    2525#ifndef XAPIAN_INCLUDED_QUERY_H
    2626#define XAPIAN_INCLUDED_QUERY_H
    2727
    28 #include <map>
    2928#include <string>
    3029#include <vector>
    3130
     
    4544namespace Xapian {
    4645
    4746class PostingSource;
     47class SerialisationContext;
    4848
    4949/** Class representing a query.
    5050 *
     
    259259        std::string serialise() const;
    260260
    261261        /** Unserialise a query from a string produced by serialise().
    262          *  FIXME - need to add a way to register posting sources.  See ticket #206
     262         *
     263         *  This method will fail if the query contains any external
     264         *  PostingSource leaf nodes.
     265         *
     266         *  @param s The string representing the serialised query.
    263267         */
    264268        static Query unserialise(const std::string &s);
    265269
     270        /** Unserialise a query from a string produced by serialise().
     271         *
     272         *  The supplied context will be used to unserialise any external
     273         *  PostingSource leaf nodes.
     274         *
     275         *  @param s The string representing the serialised query.
     276         *  @param ctx A context to use when unserialising the query.
     277         */
     278        static Query unserialise(const std::string & s, const SerialisationContext & ctx);
     279
    266280        /// Return a string describing this object.
    267281        std::string get_description() const;
    268282
     
    434448        ~Internal();
    435449
    436450        static Xapian::Query::Internal * unserialise(const std::string &s,
    437                 const std::map<std::string, Xapian::PostingSource *> &sources);
     451                                                     const SerialisationContext & ctx);
    438452
    439453        /** Add a subquery.
    440454         */
  • xapian-core/include/xapian/enquire.h

     
    10111011
    10121012namespace Xapian {
    10131013
     1014class SerialisationContext;
     1015
    10141016/// Abstract base class for weighting schemes
    10151017class XAPIAN_VISIBILITY_DEFAULT Weight {
    10161018    friend class Enquire; // So Enquire can clone us
    10171019    friend class ::RemoteServer; // So RemoteServer can clone us - FIXME
     1020    friend class SerialisationContext;
    10181021    friend class ::ScaleWeight;
    10191022    public:
    10201023        class Internal;
  • xapian-core/include/xapian/serialisationcontext.h

     
     1/** @file serialisationcontext.h
     2 * @brief Context for looking up objects during unserialisation.
     3 */
     4/* Copyright 2009 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
     19 * USA
     20 */
     21
     22#ifndef XAPIAN_INCLUDED_SERIALISATIONCONTEXT_H
     23#define XAPIAN_INCLUDED_SERIALISATIONCONTEXT_H
     24
     25#include <xapian/base.h>
     26#include <xapian/visibility.h>
     27#include <string>
     28
     29namespace Xapian {
     30
     31// Forward declarations.
     32class Weight;
     33class PostingSource;
     34
     35/** A context for serialisation.
     36 *
     37 *  This context is used to look up weighting schemes and posting sources when
     38 *  unserialising.
     39 */
     40class XAPIAN_VISIBILITY_DEFAULT SerialisationContext {
     41  public:
     42    /// Class holding details of the context.
     43    class Internal;
     44
     45  private:
     46    /// @private @internal Reference counted internals.
     47    Xapian::Internal::RefCntPtr<Internal> internal;
     48
     49  public:
     50    /** Copy the context - the copy is shallow.
     51     */
     52    SerialisationContext(const SerialisationContext & other);
     53
     54    /** Assign to the context - the copy is shallow.
     55     */
     56    SerialisationContext & operator=(const SerialisationContext & other);
     57
     58    /** Default constructor: makes a context with default settings.
     59     *
     60     *  The context will contain all hardcoded weighting schemes and
     61     *  posting sources.
     62     */
     63    SerialisationContext();
     64
     65    /** Destructor.
     66     *
     67     *  This is essentially the same as the default destructor, but
     68     *  needs to be explicitly defined because the definition of the
     69     *  internals is not visible externally, which results in an error
     70     *  if when the compiler tries to generate a default destructor.
     71     */
     72    ~SerialisationContext();
     73
     74    /** Clear all registered weighting schemes from the context.
     75     */
     76    void clear_weighting_schemes();
     77
     78    /** Register a weighting scheme with the context.
     79     */
     80    void register_weighting_scheme(const Xapian::Weight &wt);
     81
     82    /** Get a weighting scheme given a name.
     83     *
     84     *  The returned weighting scheme is owned by the context object.
     85     *
     86     *  Returns NULL if the weighting scheme could not be found.
     87     */
     88    const Xapian::Weight *
     89            get_weighting_scheme(const std::string & name) const;
     90
     91    /** Clear all registered posting sources from the context.
     92     */
     93    void clear_posting_sources();
     94
     95    /** Register a user-defined posting source class.
     96     */
     97    void register_posting_source(const Xapian::PostingSource &source);
     98
     99    /** Get a posting source given a name.
     100     *
     101     *  The returned posting source is owned by the context object.
     102     *
     103     *  Returns NULL if the posting source could not be found.
     104     */
     105    const Xapian::PostingSource *
     106            get_posting_source(const std::string & name) const;
     107};
     108
     109}
     110
     111#endif /* XAPIAN_INCLUDED_SERIALISATIONCONTEXT_H */
  • xapian-core/include/Makefile.mk

    Property changes on: xapian-core/include/xapian/serialisationcontext.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
    2525        include/xapian/query.h\
    2626        include/xapian/queryparser.h\
    2727        include/xapian/replication.h\
     28        include/xapian/serialisationcontext.h\
    2829        include/xapian/sorter.h\
    2930        include/xapian/stem.h\
    3031        include/xapian/termgenerator.h\
  • xapian-core/include/xapian.h

     
    5454// Stemming
    5555#include <xapian/stem.h>
    5656
     57// Serialisation support
     58#include <xapian/serialisationcontext.h>
     59
    5760// Unicode support
    5861#include <xapian/unicode.h>
    5962
  • xapian-core/net/remoteserver.cc

     
    3232#include <stdlib.h>
    3333
    3434#include "autoptr.h"
     35#include "serialisationcontextinternal.h"
    3536#include "multimatch.h"
    3637#include "omassert.h"
    3738#include "omtime.h"
     
    105106    message += encode_length(uuid.size());
    106107    message += uuid;
    107108    send_message(REPLY_GREETING, message);
    108 
    109     // Register weighting schemes.
    110     Xapian::Weight * weight;
    111     weight = new Xapian::BM25Weight;
    112     wtschemes[weight->name()] = weight;
    113     weight = new Xapian::BoolWeight;
    114     wtschemes[weight->name()] = weight;
    115     weight = new Xapian::TradWeight;
    116     wtschemes[weight->name()] = weight;
    117 
    118     Xapian::PostingSource * source;
    119     source = new Xapian::ValueWeightPostingSource(0);
    120     postingsources[source->name()] = source;
    121     source = new Xapian::ValueMapPostingSource(0);
    122     postingsources[source->name()] = source;
    123     source = new Xapian::FixedWeightPostingSource(0.0);
    124     postingsources[source->name()] = source;
    125109}
    126110
    127111RemoteServer::~RemoteServer()
    128112{
    129113    delete db;
    130114    // wdb is either NULL or equal to db, so we shouldn't delete it too!
    131 
    132     {
    133         map<string, Xapian::Weight*>::const_iterator i;
    134         for (i = wtschemes.begin(); i != wtschemes.end(); ++i) {
    135             delete i->second;
    136         }
    137     }
    138 
    139     {
    140         map<string, Xapian::PostingSource *>::const_iterator i;
    141         for (i = postingsources.begin(); i != postingsources.end(); ++i) {
    142             delete i->second;
    143         }
    144     }
    145115}
    146116
    147117message_type
     
    382352
    383353    // Unserialise the Query.
    384354    len = decode_length(&p, p_end, true);
    385     AutoPtr<Xapian::Query::Internal> query(Xapian::Query::Internal::unserialise(string(p, len), postingsources));
     355    AutoPtr<Xapian::Query::Internal> query(Xapian::Query::Internal::unserialise(string(p, len), ctx));
    386356    p += len;
    387357
    388358    // Unserialise assorted Enquire settings.
     
    421391
    422392    // Unserialise the Weight object.
    423393    len = decode_length(&p, p_end, true);
    424     map<string, Xapian::Weight *>::const_iterator i;
    425     i = wtschemes.find(string(p, len));
    426     if (i == wtschemes.end()) {
     394    const Xapian::Weight * wttype = ctx.get_weighting_scheme(string(p, len));
     395    if (wttype == NULL) {
    427396        throw Xapian::InvalidArgumentError("Weighting scheme " + string(p, len) + " not registered");
    428397    }
    429398    p += len;
    430399
    431400    len = decode_length(&p, p_end, true);
    432     AutoPtr<Xapian::Weight> wt(i->second->unserialise(string(p, len)));
     401    AutoPtr<Xapian::Weight> wt(wttype->unserialise(string(p, len)));
    433402    p += len;
    434403
    435404    // Unserialise the RSet object.
     
    627596
    628597    send_message(REPLY_ADDDOCUMENT, encode_length(did));
    629598}
    630 
    631 
    632 void
    633 RemoteServer::register_posting_source(const Xapian::PostingSource &source)
    634 {
    635     if (source.name().empty()) {
    636         throw Xapian::InvalidOperationError("Unable to register posting source - name() method returns empty string.");
    637     }
    638     Xapian::PostingSource * sourceclone = source.clone();
    639     if (!sourceclone) {
    640         throw Xapian::InvalidOperationError("Unable to register posting source - clone() method returns NULL.");
    641     }
    642     try {
    643         postingsources[source.name()] = sourceclone;
    644     } catch(...) {
    645         delete sourceclone;
    646         throw;
    647     }
    648 }
  • xapian-core/common/Makefile.mk

     
    5050        common/safeuuid.h\
    5151        common/safewindows.h\
    5252        common/safewinsock2.h\
     53        common/serialisationcontextinternal.h\
    5354        common/serialise-double.h\
    5455        common/serialise.h\
    5556        common/socket_utils.h\
  • xapian-core/common/remoteserver.h

     
    2222#ifndef XAPIAN_INCLUDED_REMOTESERVER_H
    2323#define XAPIAN_INCLUDED_REMOTESERVER_H
    2424
     25#include "xapian/serialisationcontext.h"
    2526#include "xapian/database.h"
    2627#include "xapian/enquire.h"
    2728#include "xapian/postingsource.h"
     
    6566     */
    6667    Xapian::timeout idle_timeout;
    6768
    68     /// Registered weighting schemes.
    69     map<string, Xapian::Weight *> wtschemes;
     69    /** The context, used for registering weight schemes and posting
     70     *  sources.
     71     */
     72    Xapian::SerialisationContext ctx;
    7073
    71     /// Registered external posting sources.
    72     map<string, Xapian::PostingSource *> postingsources;
    73 
    7474    /// Accept a message from the client.
    7575    message_type get_message(Xapian::timeout timeout, string & result,
    7676                             message_type required_type = MSG_MAX);
     
    172172
    173173    /// Register a user-defined weighting scheme class.
    174174    void register_weighting_scheme(const Xapian::Weight &wt) {
    175         wtschemes[wt.name()] = wt.clone();
     175        ctx.register_weighting_scheme(wt);
    176176    }
    177177
    178178    /** Register a user-defined posting source class.
    179179     */
    180     void register_posting_source(const Xapian::PostingSource &source);
     180    void register_posting_source(const Xapian::PostingSource &source) {
     181        ctx.register_posting_source(source);
     182    }
    181183};
    182184
    183185#endif // XAPIAN_INCLUDED_REMOTESERVER_H
  • xapian-core/common/serialisationcontextinternal.h

     
     1/** @file serialisationcontextinternal.h
     2 * @brief Internals of SerialisationContext object.
     3 */
     4/* Copyright 2009 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#ifndef XAPIAN_INCLUDED_SERIALISATIONCONTEXTINTERNAL_H
     22#define XAPIAN_INCLUDED_SERIALISATIONCONTEXTINTERNAL_H
     23
     24#include "xapian/base.h"
     25#include "xapian/serialisationcontext.h"
     26
     27#include <map>
     28#include <string>
     29
     30class Xapian::Weight;
     31class Xapian::PostingSource;
     32
     33class Xapian::SerialisationContext::Internal
     34        : public Xapian::Internal::RefCntBase {
     35    /// Registered weighting schemes.
     36    std::map<std::string, Xapian::Weight *> wtschemes;
     37
     38    /// Registered external posting sources.
     39    std::map<std::string, Xapian::PostingSource *> postingsources;
     40
     41    /** Add the hardcoded default weighting schemes and posting sources.
     42     */
     43    void add_defaults();
     44
     45  public:
     46    Internal();
     47
     48    /** Clear all registered weighting schemes from the context.
     49     */
     50    void clear_weighting_schemes();
     51
     52    /** Register a weighting scheme with the context.
     53     */
     54    void register_weighting_scheme(const Xapian::Weight &wt);
     55
     56    /** Get a weighting scheme given a name.
     57     *
     58     *  The returned weighting scheme is owned by the context object.
     59     *
     60     *  Returns NULL if the weighting scheme could not be found.
     61     */
     62    const Xapian::Weight *
     63            get_weighting_scheme(const std::string & name) const;
     64
     65    /** Clear all registered posting sources from the context.
     66     */
     67    void clear_posting_sources();
     68
     69    /** Register a user-defined posting source class.
     70     */
     71    void register_posting_source(const Xapian::PostingSource &source);
     72
     73    /** Get a posting source given a name.
     74     *
     75     *  The returned posting source is owned by the context object.
     76     *
     77     *  Returns NULL if the posting source could not be found.
     78     */
     79    const Xapian::PostingSource *
     80            get_posting_source(const std::string & name) const;
     81};
     82
     83#endif // XAPIAN_INCLUDED_SERIALISATIONCONTEXTINTERNAL_H
  • xapian-core/api/Makefile.mk

    Property changes on: xapian-core/common/serialisationcontextinternal.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
    2525        api/postingsource.cc\
    2626        api/postlist.cc\
    2727        api/replication.cc\
     28        api/serialisationcontext.cc\
    2829        api/sortable-serialise.cc\
    2930        api/sorter.cc\
    3031        api/termlist.cc\
  • xapian-core/api/serialisationcontext.cc

     
     1/** @file serialisationcontext.cc
     2 * @brief Context for looking up objects during unserialisation.
     3 */
     4/* Copyright (C) 2009 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#include <config.h>
     22#include "xapian/serialisationcontext.h"
     23
     24#include "xapian/enquire.h"
     25#include "xapian/error.h"
     26#include "xapian/postingsource.h"
     27#include "serialisationcontextinternal.h"
     28#include "omdebug.h"
     29
     30namespace Xapian {
     31
     32SerialisationContext::SerialisationContext(const SerialisationContext & other)
     33        : internal(other.internal)
     34{
     35    LOGCALL_CTOR(API, "Xapian::SerialisationContext::SerialisationContext", other);
     36}
     37
     38SerialisationContext &
     39SerialisationContext::operator=(const SerialisationContext & other)
     40{
     41    LOGCALL(API, Xapian::SerialisationContext &,
     42            "Xapian::SerialisationContext::operator=", other);
     43    internal = other.internal;
     44    RETURN(*this);
     45}
     46
     47SerialisationContext::SerialisationContext()
     48        : internal(new SerialisationContext::Internal())
     49{
     50    LOGCALL_CTOR(API, "Xapian::SerialisationContext::SerialisationContext",
     51                 "");
     52}
     53
     54SerialisationContext::~SerialisationContext()
     55{
     56    LOGCALL_DTOR(API, "Xapian::SerialisationContext::~SerialisationContext");
     57}
     58
     59void
     60SerialisationContext::clear_weighting_schemes()
     61{
     62    LOGCALL_VOID(API,
     63                 "Xapian::SerialisationContext::clear_weighting_schemes",
     64                 "");
     65    internal->clear_weighting_schemes();
     66}
     67
     68void
     69SerialisationContext::register_weighting_scheme(const Xapian::Weight &wt)
     70{
     71    LOGCALL_VOID(API,
     72                 "Xapian::SerialisationContext::register_weighting_scheme",
     73                 wt);
     74    internal->register_weighting_scheme(wt);
     75}
     76
     77const Xapian::Weight *
     78SerialisationContext::get_weighting_scheme(const std::string & name) const
     79{
     80    LOGCALL(API,
     81            const Xapian::Weight *,
     82            "Xapian::SerialisationContext::get_weighting_scheme",
     83            name);
     84    RETURN(internal->get_weighting_scheme(name));
     85}
     86
     87void
     88SerialisationContext::clear_posting_sources()
     89{
     90    LOGCALL_VOID(API, "Xapian::SerialisationContext::clear_posting_sources", "");
     91    internal->clear_posting_sources();
     92}
     93
     94void
     95SerialisationContext::register_posting_source(const Xapian::PostingSource &source)
     96{
     97    LOGCALL_VOID(API, "Xapian::SerialisationContext::register_posting_source", source);
     98    internal->register_posting_source(source);
     99}
     100
     101const Xapian::PostingSource *
     102SerialisationContext::get_posting_source(const std::string & name) const
     103{
     104    LOGCALL(API,
     105            const Xapian::PostingSource *,
     106            "Xapian::SerialisationContext::get_posting_source",
     107            name);
     108    RETURN(internal->get_posting_source(name));
     109}
     110
     111
     112SerialisationContext::Internal::Internal()
     113        : Xapian::Internal::RefCntBase(),
     114          wtschemes(),
     115          postingsources()
     116{
     117    add_defaults();
     118}
     119
     120void
     121SerialisationContext::Internal::add_defaults()
     122{
     123    Xapian::Weight * weight;
     124    weight = new Xapian::BM25Weight;
     125    wtschemes[weight->name()] = weight;
     126    weight = new Xapian::BoolWeight;
     127    wtschemes[weight->name()] = weight;
     128    weight = new Xapian::TradWeight;
     129    wtschemes[weight->name()] = weight;
     130
     131    Xapian::PostingSource * source;
     132    source = new Xapian::ValueWeightPostingSource(0);
     133    postingsources[source->name()] = source;
     134    source = new Xapian::ValueMapPostingSource(0);
     135    postingsources[source->name()] = source;
     136    source = new Xapian::FixedWeightPostingSource(0.0);
     137    postingsources[source->name()] = source;
     138}
     139
     140void
     141SerialisationContext::Internal::clear_weighting_schemes()
     142{
     143    std::map<std::string, Xapian::Weight*>::const_iterator i;
     144    for (i = wtschemes.begin(); i != wtschemes.end(); ++i) {
     145        delete i->second;
     146    }
     147}
     148
     149void
     150SerialisationContext::Internal::register_weighting_scheme(const Xapian::Weight &wt)
     151{
     152// FIXME - delete old wtschemes[wt.name()].
     153    wtschemes[wt.name()] = wt.clone();
     154}
     155
     156const Xapian::Weight *
     157SerialisationContext::Internal::get_weighting_scheme(const std::string & name) const
     158{
     159    std::map<std::string, Xapian::Weight *>::const_iterator i;
     160    i = wtschemes.find(name);
     161    if (i == wtschemes.end()) {
     162        return NULL;
     163    }
     164    return i->second;
     165}
     166
     167void
     168SerialisationContext::Internal::clear_posting_sources()
     169{
     170    std::map<std::string, Xapian::PostingSource *>::const_iterator i;
     171    for (i = postingsources.begin(); i != postingsources.end(); ++i) {
     172        delete i->second;
     173    }
     174}
     175
     176void
     177SerialisationContext::Internal::register_posting_source(const Xapian::PostingSource &source)
     178{
     179    std::string sourcename = source.name();
     180    if (sourcename.empty()) {
     181        throw Xapian::InvalidOperationError("Unable to register posting source - name() method returns empty string.");
     182    }
     183    Xapian::PostingSource * sourceclone = source.clone();
     184    if (!sourceclone) {
     185        throw Xapian::InvalidOperationError("Unable to register posting source - clone() method returns NULL.");
     186    }
     187    try {
     188// FIXME - delete old postingsources[sourcename].
     189        postingsources[sourcename] = sourceclone;
     190    } catch(...) {
     191        delete sourceclone;
     192        throw;
     193    }
     194}
     195
     196const Xapian::PostingSource *
     197SerialisationContext::Internal::get_posting_source(const std::string & name) const
     198{
     199    std::map<std::string, Xapian::PostingSource *>::const_iterator i;
     200    i = postingsources.find(name);
     201    if (i == postingsources.end()) {
     202        return NULL;
     203    }
     204    return i->second;
     205}
     206
     207}
  • xapian-core/api/omqueryinternal.cc

    Property changes on: xapian-core/api/serialisationcontext.cc
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
    2525
    2626#include "omqueryinternal.h"
    2727
     28#include "serialisationcontextinternal.h"
    2829#include "omdebug.h"
    2930#include "utils.h"
    3031#include "serialise.h"
     
    391392    const char *p;
    392393    const char *end;
    393394    Xapian::termpos curpos;
    394     const map<string, Xapian::PostingSource *> & sources;
     395    const Xapian::SerialisationContext & ctx;
    395396
    396397    Xapian::Query::Internal * readquery();
    397398    Xapian::Query::Internal * readexternal();
     
    399400
    400401  public:
    401402    QUnserial(const string & s,
    402               const map<string, Xapian::PostingSource *> & sources_)
    403             : p(s.c_str()), end(p + s.size()), curpos(1), sources(sources_) { }
     403              const Xapian::SerialisationContext & ctx_)
     404            : p(s.c_str()), end(p + s.size()), curpos(1), ctx(ctx_) { }
    404405    Xapian::Query::Internal * decode();
    405406};
    406407
     
    457458
    458459    size_t length = decode_length(&p, end, true);
    459460    string sourcename(p, length);
    460     map<string, Xapian::PostingSource *>::const_iterator i;
    461     i = sources.find(sourcename);
    462     if (i == sources.end()) {
    463         throw Xapian::InvalidArgumentError("PostingSource " + string(p, length) + " not registered");
     461    const Xapian::PostingSource * source = ctx.get_posting_source(sourcename);
     462    if (source == NULL) {
     463        throw Xapian::InvalidArgumentError("PostingSource " + sourcename +
     464                                          " not registered");
    464465    }
    465466
    466467    p += length;
     
    468469    string sourcedata(p, length);
    469470    p += length;
    470471
    471     return new Xapian::Query::Internal(i->second->unserialise(sourcedata), true);
     472    return new Xapian::Query::Internal(source->unserialise(sourcedata), true);
    472473}
    473474
    474475static Xapian::Query::Internal *
     
    606607
    607608Xapian::Query::Internal *
    608609Xapian::Query::Internal::unserialise(const string &s,
    609                         const map<string, Xapian::PostingSource *> & sources)
     610                const Xapian::SerialisationContext & ctx)
    610611{
    611612    Assert(s.length() > 1);
    612     QUnserial u(s, sources);
     613    QUnserial u(s, ctx);
    613614    Xapian::Query::Internal * qint = u.decode();
    614615    AssertEq(s, qint->serialise());
    615616    return qint;
     
    617618#else
    618619Xapian::Query::Internal *
    619620Xapian::Query::Internal::unserialise(const string &,
    620                         const map<string, Xapian::PostingSource *> & sources)
     621                const Xapian::SerialisationContext & ctx)
    621622{
    622623    throw Xapian::InternalError("query serialisation not compiled in");
    623624}
  • xapian-core/api/omquery.cc

     
    3030
    3131#include "xapian/error.h"
    3232#include "xapian/postingsource.h"
     33#include "xapian/serialisationcontext.h"
    3334#include "xapian/termiterator.h"
    3435
    3536#include <vector>
     
    216217    DEBUGAPICALL_STATIC(Xapian::Query, "Xapian::Query::unserialise", s);
    217218    Query result;
    218219    if (!s.empty()) {
    219         std::map<std::string, Xapian::PostingSource *> sources;
    220         result.internal = Xapian::Query::Internal::unserialise(s, sources);
     220        SerialisationContext ctx;
     221        result.internal = Xapian::Query::Internal::unserialise(s, ctx);
    221222    }
    222223    RETURN(result);
    223224}
    224225
     226Query
     227Query::unserialise(const std::string & s, const SerialisationContext & ctx)
     228{
     229    DEBUGAPICALL_STATIC(Xapian::Query, "Xapian::Query::unserialise",
     230                        s << ", ctx");
     231    Query result;
     232    if (!s.empty()) {
     233        result.internal = Xapian::Query::Internal::unserialise(s, ctx);
     234    }
     235    RETURN(result);
     236}
     237
     238
    225239std::string
    226240Query::get_description() const
    227241{
  • xapian-bindings/csharp/Makefile.am

     
    4444        SWIGTYPE_p_std__string.cs \
    4545        SWIGTYPE_p_std__vectorT_std__string_t.cs \
    4646        SWIGTYPE_p_std__vectorT_Xapian__Query_t.cs \
     47        SerialisationContext.cs \
    4748        SimpleStopper.cs \
    4849        Sorter.cs \
    4950        Stem.cs \
  • xapian-bindings/xapian.i

     
    812812%include <xapian/replication.h>
    813813%include <xapian/valuesetmatchdecider.h>
    814814
     815%ignore Xapian::SerialisationContext::operator=;
     816%include <xapian/serialisationcontext.h>
     817
    815818namespace Xapian {
    816819
    817820#if defined SWIGPYTHON