Ticket #110: xapian-fix-inconsistent-paging-with-sort-by-relevance-then-value.patch

File xapian-fix-inconsistent-paging-with-sort-by-relevance-then-value.patch, 3.6 KB (added by Olly Betts, 17 years ago)

Patch to fix this for 0.9.9

  • matcher/multimatch.cc

     
    22 *
    33 * Copyright 1999,2000,2001 BrightStation PLC
    44 * Copyright 2001,2002 Ananova Ltd
    5  * Copyright 2002,2003,2004,2005,2006 Olly Betts
     5 * Copyright 2002,2003,2004,2005,2006,2007 Olly Betts
    66 * Copyright 2003 Orange PCS Ltd
    77 * Copyright 2003 Sam Liddicott
    88 *
     
    6161
    6262using namespace std;
    6363
     64const Xapian::Enquire::Internal::sort_setting REL =
     65        Xapian::Enquire::Internal::REL;
     66const Xapian::Enquire::Internal::sort_setting REL_VAL =
     67        Xapian::Enquire::Internal::REL_VAL;
     68const Xapian::Enquire::Internal::sort_setting VAL =
     69        Xapian::Enquire::Internal::VAL;
     70const Xapian::Enquire::Internal::sort_setting VAL_REL =
     71        Xapian::Enquire::Internal::VAL_REL;
     72
    6473////////////////////////////////////
    6574// Initialisation and cleaning up //
    6675////////////////////////////////////
     
    139148                rem_db->set_query(query, qlen, collapse_key, order, sort_key,
    140149                                  sort_by, sort_value_forward, percent_cutoff,
    141150                                  weight_cutoff, weight, *subrset);
     151                bool decreasing_relevance =
     152                    (sort_by == REL || sort_by == REL_VAL);
    142153                smatch = new RemoteSubMatch(rem_db, gatherer.get(),
    143                                             sort_key != Xapian::valueno(-1));
     154                                            !decreasing_relevance);
    144155            } else {
    145156#endif /* XAPIAN_HAS_REMOTE_BACKEND */
    146157                smatch = new LocalSubMatch(subdb, query, qlen, *subrset, gatherer.get(), weight);
     
    417428
    418429        DEBUGLINE(MATCH, "Candidate document id " << did << " wt " << wt);
    419430        Xapian::Internal::MSetItem new_item(wt, did);
    420         if (sort_key != Xapian::valueno(-1)) {
     431        if (sort_by != REL) {
    421432            const unsigned int multiplier = db.internal.size();
    422433            Assert(multiplier != 0);
    423434            Xapian::doccount n = (new_item.did - 1) % multiplier; // which actual database
     
    428439
    429440        // Test if item has high enough weight (or sort key) to get into
    430441        // proto-mset.
    431         if (sort_key != Xapian::valueno(-1) || min_item.wt > 0.0)
     442        if (sort_by != REL || min_item.wt > 0.0)
    432443            if (!mcmp(new_item, min_item)) continue;
    433444
    434445        Xapian::Internal::RefCntPtr<Xapian::Document::Internal> doc;
     
    476487                } else {
    477488                    ++duplicates_found;
    478489                    Xapian::Internal::MSetItem &old_item = oldkey->second.first;
    479                     // FIXME: what about sort_key != Xapian::valueno(-1) case
    480                     // here?
     490                    // FIXME: what about the (sort_by != REL) case here?
    481491                    if (mcmp(old_item, new_item)) {
    482492                        DEBUGLINE(MATCH, "collapsem: better exists: " <<
    483493                                  new_item.collapse_key);
     
    495505
    496506                    // This is best match with this key so far:
    497507                    // remove the old one from the MSet
    498                     if ((sort_key == Xapian::valueno(-1) && min_item.wt <= 0.0) ||
     508                    if ((sort_by != VAL && min_item.wt <= 0.0) ||
    499509                        mcmp(old_item, min_item)) {
    500510                        // Old one hasn't fallen out of MSet yet
    501511                        // Scan through (unsorted) MSet looking for entry
     
    540550                pop_heap<vector<Xapian::Internal::MSetItem>::iterator,
    541551                         MSetCmp>(items.begin(), items.end(), mcmp);
    542552                items.pop_back();
    543                 if (sort_key != Xapian::valueno(-1)) {
     553                if (sort_by == REL || sort_by == REL_VAL) {
    544554                    Xapian::weight tmp = min_item.wt;
    545555                    min_item = items.front();
    546556                    min_item.wt = tmp;
     
    554564            } else {
    555565                items.push_back(new_item);
    556566                is_heap = false;
    557                 if (sort_key == Xapian::valueno(-1) && items.size() == max_msize) {
     567                if (sort_by == REL && items.size() == max_msize) {
    558568                    // We're done if this is a forward boolean match
    559569                    // (bodgetastic, FIXME better if we can)
    560570                    if (max_weight == 0 && sort_forward) break;