diff options
author | Henning Baldersheim <balder@oath.com> | 2018-02-04 17:30:35 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-02-04 17:30:35 +0100 |
commit | bf468f0a4367fb5ab9117274bcceb8ba9de59109 (patch) | |
tree | a20c562874abac13c4a3d9c51f19ee6b66df71fb /streamingvisitors | |
parent | d1c8e15ee5f8f7cc32ff92be6b881ad01a41e31a (diff) |
Rankmanager must also handle fieldsets recursively.
Diffstat (limited to 'streamingvisitors')
4 files changed, 80 insertions, 64 deletions
diff --git a/streamingvisitors/src/vespa/searchvisitor/indexenvironment.cpp b/streamingvisitors/src/vespa/searchvisitor/indexenvironment.cpp index a4ecf655c3d..53e1910b564 100644 --- a/streamingvisitors/src/vespa/searchvisitor/indexenvironment.cpp +++ b/streamingvisitors/src/vespa/searchvisitor/indexenvironment.cpp @@ -17,20 +17,33 @@ IndexEnvironment::IndexEnvironment(const ITableManager & tableManager) : { } -IndexEnvironment::~IndexEnvironment() {} +IndexEnvironment::~IndexEnvironment() = default; bool IndexEnvironment::addField(const vespalib::string & name, bool isAttribute) { - if (getFieldByName(name) != NULL) { + if (getFieldByName(name) != nullptr) { return false; } - FieldInfo info(isAttribute ? FieldType::ATTRIBUTE : FieldType::INDEX, FieldInfo::CollectionType::SINGLE, name, _fields.size()); + FieldInfo info(isAttribute ? FieldType::ATTRIBUTE : FieldType::INDEX, + FieldInfo::CollectionType::SINGLE, name, _fields.size()); info.addAttribute(); // we are able to produce needed attributes at query time _fields.push_back(info); _fieldNames[info.name()] = info.id(); return true; } +void +IndexEnvironment::hintAttributeAccess(const string & name) const { + if (name.empty()) { + return; + } + if (_motivation == RANK) { + _rankAttributes.insert(name); + } else { + _dumpAttributes.insert(name); + } +} + } // namespace storage diff --git a/streamingvisitors/src/vespa/searchvisitor/indexenvironment.h b/streamingvisitors/src/vespa/searchvisitor/indexenvironment.h index a11e5300f03..832d99b4dde 100644 --- a/streamingvisitors/src/vespa/searchvisitor/indexenvironment.h +++ b/streamingvisitors/src/vespa/searchvisitor/indexenvironment.h @@ -34,57 +34,42 @@ public: IndexEnvironment(const search::fef::ITableManager & tableManager); ~IndexEnvironment(); - // inherit documentation - virtual const search::fef::Properties & getProperties() const override { return _properties; } + const search::fef::Properties & getProperties() const override { return _properties; } - // inherit documentation - virtual uint32_t getNumFields() const override { return _fields.size(); } + uint32_t getNumFields() const override { return _fields.size(); } - // inherit documentation - virtual const search::fef::FieldInfo * getField(uint32_t id) const override { + const search::fef::FieldInfo * getField(uint32_t id) const override { if (id >= _fields.size()) { - return NULL; + return nullptr; } return &_fields[id]; } - // inherit documentation - virtual const search::fef::FieldInfo * getFieldByName(const string & name) const override { - StringInt32Map::const_iterator itr = _fieldNames.find(name); + const search::fef::FieldInfo * getFieldByName(const string & name) const override { + auto itr = _fieldNames.find(name); if (itr == _fieldNames.end()) { - return NULL; + return nullptr; } return getField(itr->second); } - // inherit documentation - virtual const search::fef::ITableManager & getTableManager() const override { return *_tableManager; } + const search::fef::ITableManager & getTableManager() const override { + return *_tableManager; + } - virtual FeatureMotivation getFeatureMotivation() const override { + FeatureMotivation getFeatureMotivation() const override { return _motivation; } - // inherit documentation - virtual void hintFeatureMotivation(FeatureMotivation motivation) const override { + void hintFeatureMotivation(FeatureMotivation motivation) const override { _motivation = motivation; } - // inherit documentation - virtual void hintFieldAccess(uint32_t) const override {} + void hintFieldAccess(uint32_t) const override {} - // inherit documentation - virtual void hintAttributeAccess(const string & name) const override { - if (name.empty()) { - return; - } - if (_motivation == RANK) { - _rankAttributes.insert(name); - } else { - _dumpAttributes.insert(name); - } - } + void hintAttributeAccess(const string & name) const override; - virtual vespalib::eval::ConstantValue::UP getConstantValue(const vespalib::string &) const override { + vespalib::eval::ConstantValue::UP getConstantValue(const vespalib::string &) const override { return vespalib::eval::ConstantValue::UP(); } diff --git a/streamingvisitors/src/vespa/searchvisitor/rankmanager.cpp b/streamingvisitors/src/vespa/searchvisitor/rankmanager.cpp index b2623adca52..4ed4e9462d3 100644 --- a/streamingvisitors/src/vespa/searchvisitor/rankmanager.cpp +++ b/streamingvisitors/src/vespa/searchvisitor/rankmanager.cpp @@ -5,6 +5,7 @@ #include <vespa/searchlib/fef/functiontablefactory.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exception.h> +#include <vespa/vsm/common/document.h> #include <vespa/log/log.h> LOG_SETUP(".searchvisitor.rankmanager"); @@ -18,6 +19,7 @@ using search::fef::Properties; using search::fef::RankSetup; using vsm::VsmfieldsHandle; using vsm::VSMAdapter; +using vsm::FieldIdTList; namespace storage { @@ -49,33 +51,50 @@ RankManager::Snapshot::detectFields(const VsmfieldsHandle & fields) } } +namespace { + +FieldIdTList +buildFieldSet(const VsmfieldsConfig::Documenttype::Index & ci, const search::fef::IIndexEnvironment & indexEnv, + const VsmfieldsConfig::Documenttype::IndexVector & indexes) +{ + LOG(spam, "Index %s with %zd fields", ci.name.c_str(), ci.field.size()); + FieldIdTList ifm; + for (const VsmfieldsConfig::Documenttype::Index::Field & cf : ci.field) { + LOG(spam, "Parsing field %s", cf.name.c_str()); + auto foundIndex = std::find_if(indexes.begin(), indexes.end(), + [&cf](const auto & v) { return v.name == cf.name;}); + if ((foundIndex != indexes.end()) && (cf.name != ci.name)) { + FieldIdTList sub = buildFieldSet(*foundIndex, indexEnv, indexes); + ifm.insert(ifm.end(), sub.begin(), sub.end()); + } else { + const FieldInfo * info = indexEnv.getFieldByName(cf.name); + if (info != nullptr) { + LOG(debug, "Adding field '%s' to view in index '%s' (field id '%u')", + cf.name.c_str(), ci.name.c_str(), info->id()); + ifm.push_back(info->id()); + } else { + LOG(warning, "Field '%s' is not registred in the index environment. " + "Cannot add to index view.", cf.name.c_str()); + } + } + } + return ifm; +} + +} + void RankManager::Snapshot::buildFieldMappings(const VsmfieldsHandle & fields) { - for (uint32_t i = 0; i < fields->documenttype.size(); ++i) { - const char * dname = fields->documenttype[i].name.c_str(); - LOG(debug, "Looking through indexes for documenttype '%s'", dname); - for (uint32_t j = 0; j < fields->documenttype[i].index.size(); ++j) { - const char * iname = fields->documenttype[i].index[j].name.c_str(); - LOG(debug, "Looking through fields for index '%s'", iname); - View view; - for (uint32_t k = 0; k < fields->documenttype[i].index[j].field.size(); ++k) { - const char * fname = fields->documenttype[i].index[j].field[k].name.c_str(); - const FieldInfo * info = _protoEnv.getFieldByName(vespalib::string(fname)); - if (info != NULL) { - LOG(debug, "Adding field '%s' to view in index '%s' (field id '%u')", - fname, iname, info->id()); - view.push_back(info->id()); - } else { - LOG(warning, "Field '%s' is not registred in the index environment. " - "Cannot add to index view.", fname); - } - } - if (_views.find(iname) == _views.end()) { + for(const VsmfieldsConfig::Documenttype & di : fields->documenttype) { + LOG(debug, "Looking through indexes for documenttype '%s'", di.name.c_str()); + for(const VsmfieldsConfig::Documenttype::Index & ci : di.index) { + FieldIdTList view = buildFieldSet(ci, _protoEnv, di.index); + if (_views.find(ci.name) == _views.end()) { std::sort(view.begin(), view.end()); // lowest field id first - _views[iname] = view; + _views[ci.name] = view; } else { - LOG(warning, "We already have a view for index '%s'. Drop the new view.", iname); + LOG(warning, "We already have a view for index '%s'. Drop the new view.", ci.name.c_str()); } } } @@ -129,6 +148,8 @@ RankManager::Snapshot::Snapshot() : _tableManager.addFactory(search::fef::ITableFactory::SP(new search::fef::FunctionTableFactory(256))); } +RankManager::Snapshot::~Snapshot() = default; + bool RankManager::Snapshot::setup(const RankManager & rm, const std::vector<NamedPropertySet> & properties) { @@ -186,16 +207,12 @@ RankManager::RankManager(VSMAdapter * const vsmAdapter) : search::features::setup_search_features(_blueprintFactory); } -RankManager::~RankManager() -{ -} +RankManager::~RankManager() = default; void RankManager::configure(const vsm::VSMConfigSnapshot & snap) { notify(snap); } - - -} // namespace storage - + +} diff --git a/streamingvisitors/src/vespa/searchvisitor/rankmanager.h b/streamingvisitors/src/vespa/searchvisitor/rankmanager.h index e4d7b26d0b9..573833a93f8 100644 --- a/streamingvisitors/src/vespa/searchvisitor/rankmanager.h +++ b/streamingvisitors/src/vespa/searchvisitor/rankmanager.h @@ -2,12 +2,12 @@ #pragma once +#include "indexenvironment.h" #include <vespa/config-rank-profiles.h> #include <vespa/searchlib/fef/blueprintfactory.h> #include <vespa/searchlib/fef/ranksetup.h> #include <vespa/searchlib/fef/tablemanager.h> #include <vespa/vsm/vsm/vsm-adapter.h> -#include "indexenvironment.h" namespace storage { @@ -50,6 +50,7 @@ public: public: typedef std::shared_ptr<Snapshot> SP; Snapshot(); + ~Snapshot(); const std::vector<NamedPropertySet> & getProperties() const { return _properties; } bool setup(const RankManager & manager, const vespa::config::search::RankProfilesConfig & cfg); bool setup(const RankManager & manager, const std::vector<NamedPropertySet> & properties); @@ -64,7 +65,7 @@ public: if (itr != _views.end()) { return &itr->second; } - return NULL; + return nullptr; } }; |