re-use bitvector if re-inited with same docid range
@@ -12,17 +12,27 @@ struct TermwiseSearch : public SearchIterator {
SearchIterator::UP search;
BitVector::UP result;
+ uint32_t my_beginid;
+ uint32_t my_first_hit;
+
+ bool same_range(uint32_t beginid, uint32_t endid) const {
+ return ((beginid == my_beginid) && endid == getEndId());
+ }
TermwiseSearch(SearchIterator::UP search_in)
- : search(std::move(search_in)), result() {}
+ : search(std::move(search_in)), result(), my_beginid(0), my_first_hit(0) {}
Trinary is_strict() const override { return IS_STRICT ? Trinary::True : Trinary::False; }
void initRange(uint32_t beginid, uint32_t endid) override {
+ if (!same_range(beginid, endid)) {
+ my_beginid = beginid;
SearchIterator::initRange(beginid, endid);
search->initRange(beginid, endid);
- setDocId(std::max(getDocId(), search->getDocId()));
+ my_first_hit = std::max(getDocId(), search->getDocId());
result = search->get_hits(beginid);
}
+ setDocId(my_first_hit);
+ }
void doSeek(uint32_t docid) override {
if (__builtin_expect(isAtEnd(docid), false)) {
setAtEnd();
