diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-05-26 10:44:10 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-05-27 10:37:50 +0000 |
commit | de4daa362edd091ca8e1b2db0559a20236447aae (patch) | |
tree | b1d9db3f23db7b4fb342bb97d97c51e015f32b8e /searchlib | |
parent | d8be0cc5b5aed6deff9d37c6336757d6f07ad34f (diff) |
wrapper for iterators needing TFMDA in constructor
Diffstat (limited to 'searchlib')
5 files changed, 83 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp index 4febe165665..27aa070d514 100644 --- a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp @@ -5,6 +5,7 @@ #include <vespa/searchlib/queryeval/booleanmatchiteratorwrapper.h> #include <vespa/searchlib/queryeval/intermediate_blueprints.h> #include <vespa/searchlib/queryeval/equiv_blueprint.h> +#include <vespa/searchlib/queryeval/filter_wrapper.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/log/log.h> @@ -96,4 +97,17 @@ DiskTermBlueprint::createLeafSearch(const TermFieldMatchDataArray & tfmda, bool return search; } +SearchIterator::UP +DiskTermBlueprint::createFilterSearch(bool strict, FilterConstraint) const +{ + auto wrapper = std::make_unique<queryeval::FilterWrapper>(getState()); + auto & tfmda = wrapper->tfmda(); + if (_bitVector) { + wrapper->wrap(BitVectorIterator::create(_bitVector.get(), *tfmda[0], strict)); + } else { + wrapper->wrap(_postingHandle->createIterator(_lookupRes->counts, tfmda, _useBitVector)); + } + return wrapper; } + +} // namespace diff --git a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h index 39ac27bc448..4d6ef4589df 100644 --- a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h +++ b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h @@ -41,6 +41,8 @@ public: std::unique_ptr<queryeval::SearchIterator> createLeafSearch(const fef::TermFieldMatchDataArray & tfmda, bool strict) const override; void fetchPostings(const queryeval::ExecuteInfo &execInfo) override; + + std::unique_ptr<queryeval::SearchIterator> createFilterSearch(bool strict, FilterConstraint) const override; }; } diff --git a/searchlib/src/vespa/searchlib/queryeval/CMakeLists.txt b/searchlib/src/vespa/searchlib/queryeval/CMakeLists.txt index 5f8c2514f49..c6ca41a2a2a 100644 --- a/searchlib/src/vespa/searchlib/queryeval/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/queryeval/CMakeLists.txt @@ -19,6 +19,7 @@ vespa_add_library(searchlib_queryeval OBJECT fake_search.cpp fake_searchable.cpp field_spec.cpp + filter_wrapper.cpp full_search.cpp get_weight_from_node.cpp global_filter.cpp diff --git a/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.cpp b/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.cpp new file mode 100644 index 00000000000..9128fccd20f --- /dev/null +++ b/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.cpp @@ -0,0 +1,3 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "filter_wrapper.h" diff --git a/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.h b/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.h new file mode 100644 index 00000000000..b67bacca118 --- /dev/null +++ b/searchlib/src/vespa/searchlib/queryeval/filter_wrapper.h @@ -0,0 +1,63 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "searchiterator.h" +#include "blueprint.h" +#include <vespa/searchlib/fef/termfieldmatchdata.h> +#include <vespa/searchlib/fef/termfieldmatchdataarray.h> + +namespace search::queryeval { + +/** + * Wraps an iterator for use as a filter search. + * Owns TermFieldMatchData the wrapped iterator + * can wire to, and write to if necessary. + **/ +class FilterWrapper : public SearchIterator { +private: + std::vector<fef::TermFieldMatchData> _unused_md; + fef::TermFieldMatchDataArray _tfmda; + std::unique_ptr<SearchIterator> _wrapped_search; +public: + FilterWrapper(const Blueprint::State &state) + : _unused_md(state.numFields()), + _tfmda(), + _wrapped_search() + { + for (size_t i = 0; i < state.numFields(); ++i) { + _tfmda.add(&_unused_md[i]); + } + } + const fef::TermFieldMatchDataArray& tfmda() const { return _tfmda; } + void wrap(std::unique_ptr<SearchIterator> wrapped) { + _wrapped_search = std::move(wrapped); + } + void wrap(SearchIterator *wrapped) { + _wrapped_search.reset(wrapped); + } + void doSeek(uint32_t docid) override { + _wrapped_search->seek(docid); // use outer seek for most robustness + setDocId(_wrapped_search->getDocId()); // propagate current iterator docid + } + void doUnpack(uint32_t) override {} + void initRange(uint32_t begin_id, uint32_t end_id) override { + SearchIterator::initRange(begin_id, end_id); + _wrapped_search->initRange(begin_id, end_id); + setDocId(_wrapped_search->getDocId()); + } + void or_hits_into(BitVector &result, uint32_t begin_id) override { + _wrapped_search->or_hits_into(result, begin_id); + } + void and_hits_into(BitVector &result, uint32_t begin_id) override { + _wrapped_search->and_hits_into(result, begin_id); + } + BitVector::UP get_hits(uint32_t begin_id) override { + return _wrapped_search->get_hits(begin_id); + } + Trinary is_strict() const override { + return _wrapped_search->is_strict(); + } +}; + +} // namespace |