Ticket #674: remote-sort-key.patch

File remote-sort-key.patch, 4.9 KB (added by Olly Betts, 10 years ago)

seems to fix it, but changes mset serialisation

  • xapian-core/api/postlist.cc

    diff --git a/xapian-core/api/postlist.cc b/xapian-core/api/postlist.cc
    index 2684913..8c259e9 100644
    a b PostingIterator::Internal::get_wdf() const  
    4747}
    4848
    4949const string *
     50PostingIterator::Internal::get_sort_key() const
     51{
     52    return NULL;
     53}
     54
     55const string *
    5056PostingIterator::Internal::get_collapse_key() const
    5157{
    5258    return NULL;
  • xapian-core/api/postlist.h

    diff --git a/xapian-core/api/postlist.h b/xapian-core/api/postlist.h
    index f5814f3..350762d 100644
    a b class Xapian::PostingIterator::Internal : public Xapian::Internal::intrusive_bas  
    9595    /// Return the weight contribution for the current position.
    9696    virtual double get_weight() const = 0;
    9797
     98    virtual const std::string * get_sort_key() const;
     99
    98100    /** If the collapse key is already known, return it.
    99101     *
    100102     *  This is implemented by MSetPostList (and MergePostList).  Other
  • xapian-core/matcher/mergepostlist.cc

    diff --git a/xapian-core/matcher/mergepostlist.cc b/xapian-core/matcher/mergepostlist.cc
    index 8ff03ae..a6701ea 100644
    a b MergePostList::get_weight() const  
    151151}
    152152
    153153const string *
     154MergePostList::get_sort_key() const
     155{
     156    LOGCALL(MATCH, const string *, "MergePostList::get_sort_key", NO_ARGS);
     157    Assert(current != -1);
     158    RETURN(plists[current]->get_sort_key());
     159}
     160
     161const string *
    154162MergePostList::get_collapse_key() const
    155163{
    156164    LOGCALL(MATCH, const string *, "MergePostList::get_collapse_key", NO_ARGS);
  • xapian-core/matcher/mergepostlist.h

    diff --git a/xapian-core/matcher/mergepostlist.h b/xapian-core/matcher/mergepostlist.h
    index 2e30a2e..75755ec 100644
    a b class MergePostList : public PostList {  
    6868
    6969        Xapian::docid  get_docid() const;
    7070        double get_weight() const;
     71        const string * get_sort_key() const;
    7172        const string * get_collapse_key() const;
    7273
    7374        double get_maxweight() const;
  • xapian-core/matcher/msetpostlist.cc

    diff --git a/xapian-core/matcher/msetpostlist.cc b/xapian-core/matcher/msetpostlist.cc
    index a4702ee..bf5c004 100644
    a b MSetPostList::get_weight() const  
    8383}
    8484
    8585const string *
     86MSetPostList::get_sort_key() const
     87{
     88    LOGCALL(MATCH, const string *, "MSetPostList::get_sort_key", NO_ARGS);
     89    Assert(cursor != -1);
     90    RETURN(&mset_internal->items[cursor].sort_key);
     91}
     92
     93const string *
    8694MSetPostList::get_collapse_key() const
    8795{
    8896    LOGCALL(MATCH, const string *, "MSetPostList::get_collapse_key", NO_ARGS);
  • xapian-core/matcher/msetpostlist.h

    diff --git a/xapian-core/matcher/msetpostlist.h b/xapian-core/matcher/msetpostlist.h
    index cb9bad4..35d712d 100644
    a b class MSetPostList : public PostList {  
    6868
    6969    double get_weight() const;
    7070
     71    const string * get_sort_key() const;
     72
    7173    const string * get_collapse_key() const;
    7274
    7375    /// Not implemented for MSetPostList.
  • xapian-core/matcher/multimatch.cc

    diff --git a/xapian-core/matcher/multimatch.cc b/xapian-core/matcher/multimatch.cc
    index ef8525e..a236f26 100644
    a b MultiMatch::get_mset(Xapian::doccount first, Xapian::doccount maxitems,  
    639639        }
    640640
    641641        if (sort_by != REL) {
    642             if (sorter) {
     642            const string * ptr = pl->get_sort_key();
     643            if (ptr) {
     644                new_item.sort_key = *ptr;
     645            } else if (sorter) {
    643646                new_item.sort_key = (*sorter)(doc);
    644647            } else {
    645648                new_item.sort_key = vsdoc.get_value(sort_key);
  • xapian-core/net/serialise.cc

    diff --git a/xapian-core/net/serialise.cc b/xapian-core/net/serialise.cc
    index cdeaec3..dea8156 100644
    a b serialise_mset(const Xapian::MSet &mset)  
    172172    result += serialise_double(mset.internal->percent_factor);
    173173
    174174    result += encode_length(mset.size());
     175    size_t j = 0;
    175176    for (Xapian::MSetIterator i = mset.begin(); i != mset.end(); ++i) {
    176177        result += serialise_double(i.get_weight());
    177178        result += encode_length(*i);
     179        const string & sort_key = mset.internal->items[j++].sort_key;
     180        result += encode_length(sort_key.size());
     181        result += sort_key;
     182        result += i.get_collapse_key();
    178183        result += encode_length(i.get_collapse_key().size());
    179184        result += i.get_collapse_key();
    180185        result += encode_length(i.get_collapse_count());
    unserialise_mset(const char * p, const char * p_end)  
    207212        double wt = unserialise_double(&p, p_end);
    208213        Xapian::docid did = decode_length(&p, p_end, false);
    209214        size_t len = decode_length(&p, p_end, true);
     215        string sort_key(p, len);
     216        p += len;
     217        len = decode_length(&p, p_end, true);
    210218        string key(p, len);
    211219        p += len;
    212220        Xapian::doccount collapse_cnt = decode_length(&p, p_end, false);
    213221        items.push_back(Xapian::Internal::MSetItem(wt, did, key, collapse_cnt));
     222        swap(items.back().sort_key, sort_key);
    214223    }
    215224
    216225    AutoPtr<Xapian::Weight::Internal> stats;