diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-09-01 08:43:01 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-09-01 08:43:01 +0200 |
commit | f4f22e37f19797fa83ea1bc65efc4fe38cf4c1f0 (patch) | |
tree | 4384e5e44f0cbbaca315401ca3c7cbe12776e244 /searchlib | |
parent | 37643456fd6cda1960decaa64f3a8df9b99264a0 (diff) |
Make posting lists if it is strict or if target is filter.
If it is filter we build bitvector instead of posting list.
Diffstat (limited to 'searchlib')
4 files changed, 31 insertions, 37 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp index 0834df280fd..469a6e19659 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp +++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp @@ -1,14 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "imported_search_context.h" -#include "attributeiterators.hpp" #include "imported_attribute_vector.h" -#include "reference_attribute.h" -#include <vespa/searchcommon/attribute/search_context_params.h> -#include <vespa/searchlib/fef/fef.h> -#include <vespa/searchlib/query/queryterm.h> +#include <vespa/searchlib/common/bitvectoriterator.h> #include <vespa/searchlib/queryeval/emptysearch.h> -#include "dociditerator.h" +#include "attributeiterators.hpp" using search::datastore::EntryRef; using search::queryeval::EmptySearch; @@ -21,8 +17,7 @@ using ReverseMapping = ReferenceAttribute::ReverseMapping; using SearchContext = AttributeVector::SearchContext; -namespace search { -namespace attribute { +namespace search::attribute { ImportedSearchContext::ImportedSearchContext( std::unique_ptr<QueryTermSimple> term, @@ -59,6 +54,8 @@ ImportedSearchContext::createIterator(fef::TermFieldMatchData* matchData, bool s postings.set(&array[0], &array[array.size()]); return std::make_unique<AttributePostingListIteratorT<DocIt>>(true, matchData, postings); } + } else if (_merger.hasBitVector()) { + return BitVectorIterator::create(_merger.getBitVector(), _merger.getDocIdLimit(), *matchData, strict); } if (!strict) { return std::make_unique<AttributeIteratorT<ImportedSearchContext>>(*this, matchData); @@ -146,11 +143,15 @@ public: int32_t weight = _weight; _reverseMapping.foreach_frozen_key(_revMapIdx, [func, weight](uint32_t lid) { func(lid, weight); }); } + template <typename Func> + void foreach_key(Func func) const { + _reverseMapping.foreach_frozen_key(_revMapIdx, [func](uint32_t lid) { func(lid); }); + } }; } -void ImportedSearchContext::makeMergedPostings() +void ImportedSearchContext::makeMergedPostings(bool isFilter) { uint32_t committedTargetDocIdLimit = _target_attribute.getCommittedDocIdLimit(); std::atomic_thread_fence(std::memory_order_acquire); @@ -160,8 +161,16 @@ void ImportedSearchContext::makeMergedPostings() committedTargetDocIdLimit)); _merger.reserveArray(targetResult.weightedRefs.size(), targetResult.sizeSum); const auto &reverseMapping = _reference_attribute.getReverseMapping(); + if (isFilter) { + _merger.allocBitVector(); + } for (const auto &weightedRef : targetResult.weightedRefs) { - _merger.addToArray(ReverseMappingPostingList(reverseMapping, weightedRef.revMapIdx, weightedRef.weight)); + ReverseMappingPostingList rmp(reverseMapping, weightedRef.revMapIdx, weightedRef.weight); + if (isFilter) { + _merger.addToBitVector(rmp); + } else { + _merger.addToArray(rmp); + } } _merger.merge(); } @@ -170,8 +179,8 @@ void ImportedSearchContext::fetchPostings(bool strict) { assert(!_fetchPostingsDone); _fetchPostingsDone = true; _target_search_context->fetchPostings(strict); - if (strict) { - makeMergedPostings(); + if (strict || _target_attribute.getConfig().getIsFilter()) { + makeMergedPostings(_target_attribute.getConfig().getIsFilter()); } } @@ -191,5 +200,4 @@ const vespalib::string& ImportedSearchContext::attributeName() const { return _imported_attribute.getName(); } -} // attribute -} // search +} diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h index c142754e302..c4a6101ac0a 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h @@ -4,17 +4,12 @@ #include "attributevector.h" #include <vespa/searchcommon/attribute/i_search_context.h> -#include <vespa/vespalib/util/arrayref.h> #include <vespa/searchlib/attribute/posting_list_merger.h> -#include <memory> - -namespace search { +#include <vespa/vespalib/util/arrayref.h> -namespace fef { -class TermFieldMatchData; -} +namespace search::fef { class TermFieldMatchData; } -namespace attribute { +namespace search::attribute { class ReferenceAttribute; class ImportedAttributeVector; @@ -44,26 +39,21 @@ class ImportedSearchContext : public ISearchContext { return ((referencedLid >= _referencedLidLimit) ? 0u : referencedLid); } - void makeMergedPostings(); + void makeMergedPostings(bool isFilter); public: ImportedSearchContext(std::unique_ptr<QueryTermSimple> term, const SearchContextParams& params, const ImportedAttributeVector& imported_attribute); ~ImportedSearchContext(); - unsigned int approximateHits() const override; std::unique_ptr<queryeval::SearchIterator> createIterator(fef::TermFieldMatchData* matchData, bool strict) override; - + unsigned int approximateHits() const override; void fetchPostings(bool strict) override; - bool valid() const override; - Int64Range getAsIntegerTerm() const override; - const QueryTermBase& queryTerm() const override; - const vespalib::string& attributeName() const override; using DocId = IAttributeVector::DocId; @@ -83,5 +73,4 @@ public: } }; -} // attribute -} // search +} diff --git a/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h b/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h index 6d240d2149b..e8f2b35afb2 100644 --- a/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h +++ b/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h @@ -39,9 +39,10 @@ public: bool emptyArray() const { return _array.empty(); } vespalib::ConstArrayRef<Posting> getArray() const { return _array; } const BitVector *getBitVector() const { return _bitVector.get(); } + uint32_t getDocIdLimit() const { return _docIdLimit; } template <typename PostingListType> - void addToArray(const PostingListType postingList) + void addToArray(const PostingListType & postingList) { PostingVector &array = _array; postingList.foreach([&array](uint32_t key, const DataT &data) @@ -52,7 +53,7 @@ public: } template <typename PostingListType> - void addToBitVector(const PostingListType postingList) + void addToBitVector(const PostingListType & postingList) { BitVector &bv = *_bitVector; uint32_t limit = _docIdLimit; diff --git a/searchlib/src/vespa/searchlib/common/bitvectoriterator.h b/searchlib/src/vespa/searchlib/common/bitvectoriterator.h index ed42a47069a..d34a3354891 100644 --- a/searchlib/src/vespa/searchlib/common/bitvectoriterator.h +++ b/searchlib/src/vespa/searchlib/common/bitvectoriterator.h @@ -5,7 +5,6 @@ #include "bitvector.h" #include <vespa/searchlib/queryeval/searchiterator.h> - namespace search { namespace fef { class TermFieldMatchDataArray; } @@ -38,7 +37,4 @@ public: static UP create(const BitVector *const other, uint32_t docIdLimit, fef::TermFieldMatchData &matchData, bool strict); }; - } // namespace search - - |