diff options
author | Tor Egge <Tor.Egge@yahooinc.com> | 2023-03-24 13:36:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 13:36:55 +0100 |
commit | 92e417c34e0d0ec14809fdc3365377e9d4fa8825 (patch) | |
tree | 9c57df314e2fa2ef8751f24f1b26bdd8b38be5d0 /searchlib/src | |
parent | 9f4a7279ea632b9c77f3492d22c4cba7851d2b5e (diff) | |
parent | 17beedc12e5fa860053260c63f9c0b2495cc72ae (diff) |
Merge pull request #26569 from vespa-engine/toregge/add-empty-search-context
Add EmptySearchContext. Use it for SingleRawAttribute.
Diffstat (limited to 'searchlib/src')
5 files changed, 78 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt index 7634e954510..350beca930e 100644 --- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt @@ -40,6 +40,7 @@ vespa_add_library(searchlib_attribute OBJECT dociditerator.cpp document_weight_or_filter_search.cpp searchcontextelementiterator.cpp + empty_search_context.cpp enumattribute.cpp enumattributesaver.cpp enumcomparator.cpp diff --git a/searchlib/src/vespa/searchlib/attribute/empty_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/empty_search_context.cpp new file mode 100644 index 00000000000..7a5d82cd9ba --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/empty_search_context.cpp @@ -0,0 +1,45 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "empty_search_context.h" +#include <vespa/searchlib/queryeval/emptysearch.h> + +namespace search::attribute { + +EmptySearchContext::EmptySearchContext(const AttributeVector& attr) noexcept + : SearchContext(attr) +{ +} + +EmptySearchContext::~EmptySearchContext() = default; + +int32_t +EmptySearchContext::onFind(DocId, int32_t, int32_t&) const +{ + return -1; +} + +int32_t +EmptySearchContext::onFind(DocId, int32_t) const +{ + return -1; +} + +unsigned int +EmptySearchContext::approximateHits() const +{ + return 0u; +} + +std::unique_ptr<queryeval::SearchIterator> +EmptySearchContext::createIterator(fef::TermFieldMatchData*, bool) +{ + return std::make_unique<queryeval::EmptySearch>(); +} + +std::unique_ptr<queryeval::SearchIterator> +EmptySearchContext::createFilterIterator(fef::TermFieldMatchData*, bool) +{ + return std::make_unique<queryeval::EmptySearch>(); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/empty_search_context.h b/searchlib/src/vespa/searchlib/attribute/empty_search_context.h new file mode 100644 index 00000000000..ae6f6d76edf --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/empty_search_context.h @@ -0,0 +1,24 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "search_context.h" + +namespace search::attribute { + +/* + * EmptySearchContext is used by attribute vectors that don't support search. + */ +class EmptySearchContext : public SearchContext +{ + int32_t onFind(DocId, int32_t, int32_t&) const override; + int32_t onFind(DocId, int32_t) const override; + unsigned int approximateHits() const override; + std::unique_ptr<queryeval::SearchIterator> createIterator(fef::TermFieldMatchData*, bool) override; + std::unique_ptr<queryeval::SearchIterator> createFilterIterator(fef::TermFieldMatchData*, bool) override; +public: + EmptySearchContext(const AttributeVector& attr) noexcept; + ~EmptySearchContext(); +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp index adaf8688db5..9a514726985 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "single_raw_attribute.h" +#include "empty_search_context.h" #include "single_raw_attribute_loader.h" #include "single_raw_attribute_saver.h" #include <vespa/searchcommon/attribute/config.h> @@ -169,4 +170,10 @@ SingleRawAttribute::populate_address_space_usage(AddressSpaceUsage& usage) const usage.set(AddressSpaceComponents::raw_store, _raw_store.get_address_space_usage()); } +std::unique_ptr<attribute::SearchContext> +SingleRawAttribute::getSearch(std::unique_ptr<QueryTermSimple>, const attribute::SearchContextParams&) const +{ + return std::make_unique<EmptySearchContext>(*this); +} + } diff --git a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h index 74638821466..fa422122524 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h +++ b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h @@ -44,6 +44,7 @@ public: } bool isUndefined(DocId docid) const override; uint32_t clearDoc(DocId docId) override; + std::unique_ptr<attribute::SearchContext> getSearch(std::unique_ptr<QueryTermSimple>, const attribute::SearchContextParams&) const override; }; } |