diff options
author | Håvard Pettersen <havardpe@oath.com> | 2019-10-04 09:40:55 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2019-10-04 09:40:55 +0000 |
commit | 993e29c9e59c26616bfd966a6ec94008d5589516 (patch) | |
tree | bdfe141231f7e1d562028de92f1ef77e6188d2cd | |
parent | 4f8280c6285adafd95a8059f7440b25aa6494ac0 (diff) |
find matching elements for attribute terms searching in struct subfields
3 files changed, 27 insertions, 0 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp index 34310371755..71b1164d127 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/docsum_matcher.cpp @@ -4,6 +4,7 @@ #include <vespa/eval/eval/tensor.h> #include <vespa/eval/eval/tensor_engine.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/searchcommon/attribute/i_search_context.h> #include <vespa/searchlib/queryeval/blueprint.h> #include <vespa/searchlib/queryeval/intermediate_blueprints.h> #include <vespa/searchlib/queryeval/same_element_blueprint.h> @@ -23,6 +24,8 @@ using search::queryeval::IntermediateBlueprint; using search::queryeval::SameElementBlueprint; using search::queryeval::SearchIterator; +using AttrSearchCtx = search::attribute::ISearchContext; + namespace proton::matching { namespace { @@ -98,11 +101,29 @@ void find_matching_elements(const std::vector<uint32_t> &docs, const SameElement } } +void find_matching_elements(const std::vector<uint32_t> &docs, const vespalib::string &struct_field_name, const AttrSearchCtx &attr_ctx, MatchingElements &result) { + int32_t weight = 0; + std::vector<uint32_t> matches; + for (uint32_t i = 0; i < docs.size(); ++i) { + for (int32_t id = attr_ctx.find(docs[i], 0, weight); id >= 0; id = attr_ctx.find(docs[i], id+1, weight)) { + matches.push_back(id); + } + if (!matches.empty()) { + result.add_matching_elements(docs[i], struct_field_name, matches); + matches.clear(); + } + } +} + void find_matching_elements(const StructFieldMapper &mapper, const std::vector<uint32_t> &docs, const Blueprint &bp, MatchingElements &result) { if (auto same_element = as<SameElementBlueprint>(bp)) { if (mapper.is_struct_field(same_element->struct_field_name())) { find_matching_elements(docs, *same_element, result); } + } else if (const AttrSearchCtx *attr_ctx = bp.get_attribute_search_context()) { + if (mapper.is_struct_subfield(attr_ctx->attributeName())) { + find_matching_elements(docs, mapper.get_struct_field(attr_ctx->attributeName()), *attr_ctx, result); + } } else if (auto and_not = as<AndNotBlueprint>(bp)) { find_matching_elements(mapper, docs, and_not->getChild(0), result); } else if (auto intermediate = as<IntermediateBlueprint>(bp)) { diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp index 192d498125c..5261f568673 100644 --- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp @@ -136,6 +136,10 @@ public: } void visitMembers(vespalib::ObjectVisitor &visitor) const override; + + const attribute::ISearchContext *get_attribute_search_context() const override { + return _search_context.get(); + } }; void diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h index 2f9dbabe52e..907ea9bb066 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h @@ -14,6 +14,7 @@ namespace vespalib::slime { struct Cursor; struct Inserter; } +namespace search::attribute { class ISearchContext; } namespace search::queryeval { @@ -198,6 +199,7 @@ public: virtual bool isEquiv() const { return false; } virtual bool isWhiteList() const { return false; } virtual bool isIntermediate() const { return false; } + virtual const attribute::ISearchContext *get_attribute_search_context() const { return nullptr; } }; namespace blueprint { |