Ticket #394: positional-query-weight-check-first.patch

File positional-query-weight-check-first.patch, 2.7 KB (added by Olly Betts, 12 years ago)

simpler optimisation which works in more cases

  • xapian-core/matcher/selectpostlist.cc

    diff --git a/xapian-core/matcher/selectpostlist.cc b/xapian-core/matcher/selectpostlist.cc
    index 28f2544..a5de30d 100644
    a b SelectPostList::next(double w_min)  
    3434        PostList *p = source->next(w_min);
    3535        (void)p;
    3636        Assert(p == NULL); // AND should never prune
    37     } while (!source->at_end() && !test_doc());
     37        wt = -1;
     38    } while (!source->at_end() &&
     39             (SelectPostList::get_weight() < w_min || !test_doc()));
    3840    RETURN(NULL);
    3941}
    4042
    SelectPostList::skip_to(Xapian::docid did, double w_min)  
    4648        PostList *p = source->skip_to(did, w_min);
    4749        (void)p;
    4850        Assert(p == NULL); // AND should never prune
    49         if (!source->at_end() && !test_doc())
     51        wt = -1;
     52        if (!source->at_end() &&
     53            (SelectPostList::get_weight() < w_min || !test_doc()))
    5054            RETURN(SelectPostList::next(w_min));
    5155    }
    5256    RETURN(NULL);
    SelectPostList::check(Xapian::docid did, double w_min, bool &valid)  
    5963    PostList *p = source->check(did, w_min, valid);
    6064    (void)p;
    6165    Assert(p == NULL); // AND should never prune
    62     if (valid && !source->at_end() && !test_doc())
     66    wt = -1;
     67    if (valid && !source->at_end() &&
     68        (SelectPostList::get_weight() < w_min || !test_doc()))
    6369        valid = false;
    6470    RETURN(NULL);
    6571}
  • xapian-core/matcher/selectpostlist.h

    diff --git a/xapian-core/matcher/selectpostlist.h b/xapian-core/matcher/selectpostlist.h
    index 41151f9..c06b9e3 100644
    a b class SelectPostList : public PostList {  
    3636
    3737    protected:
    3838        PostList *source;
     39        mutable double wt;
    3940
    4041        /** Subclasses should override test_doc() with a method which returns
    4142         *  true if a document meets the appropriate criterion, false in not
    class SelectPostList : public PostList {  
    5152        Xapian::doccount get_termfreq_min() const { return 0; }
    5253        double get_maxweight() const { return source->get_maxweight(); }
    5354        Xapian::docid get_docid() const { return source->get_docid(); }
    54         double get_weight() const { return source->get_weight(); }
     55        double get_weight() const {
     56            if (wt < 0.0)
     57                wt = source->get_weight();
     58            return wt;
     59        }
    5560        Xapian::termcount get_doclength() const { return source->get_doclength(); }
    5661        double recalc_maxweight() { return source->recalc_maxweight(); }
    5762        PositionList * read_position_list() { return source->read_position_list(); }
    class SelectPostList : public PostList {  
    6469
    6570        std::string get_description() const;   
    6671   
    67         SelectPostList(PostList *source_) : source(source_) { }
     72        SelectPostList(PostList *source_) : source(source_), wt(-1) { }
    6873        ~SelectPostList() { delete source; }
    6974};
    7075