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

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

same patch backported to 1.2

  • matcher/selectpostlist.cc

     
    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
     
    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);
     
    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}
  • matcher/selectpostlist.h

     
    3535
    3636    protected:
    3737        PostList *source;
     38        mutable double wt;
    3839
    3940        /** Subclasses should override test_doc() with a method which returns
    4041         *  true if a document meets the appropriate criterion, false in not
     
    5051        Xapian::doccount get_termfreq_min() const { return 0; }
    5152        Xapian::weight get_maxweight() const { return source->get_maxweight(); }
    5253        Xapian::docid get_docid() const { return source->get_docid(); }
    53         Xapian::weight get_weight() const { return source->get_weight(); }
     54        Xapian::weight get_weight() const {
     55            if (wt < 0.0)
     56                wt = source->get_weight();
     57            return wt;
     58        }
    5459        Xapian::termcount get_doclength() const { return source->get_doclength(); }
    5560        Xapian::weight recalc_maxweight() { return source->recalc_maxweight(); }
    5661        PositionList * read_position_list() { return source->read_position_list(); }
     
    6368
    6469        std::string get_description() const;   
    6570   
    66         SelectPostList(PostList *source_) : source(source_) { }
     71        SelectPostList(PostList *source_) : source(source_), wt(-1) { }
    6772        ~SelectPostList() { delete source; }
    6873};
    6974