From aba01adff0736e99747ffc87d47c1ede7b1a8a32 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sun, 4 Feb 2018 00:16:30 +0100 Subject: Make fieldset resolution recursive. --- vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp | 48 ++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'vsm/src') diff --git a/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp b/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp index d2a92897c95..80a072df6af 100644 --- a/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp +++ b/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp @@ -21,6 +21,8 @@ using search::ConstQueryTermList; namespace vsm { +namespace { + void setMatchType(FieldSearcherContainer & searcher, vespalib::stringref arg1) { if (arg1 == "prefix") { searcher->setMatchType(FieldSearcher::PREFIX); @@ -35,6 +37,8 @@ void setMatchType(FieldSearcherContainer & searcher, vespalib::stringref arg1) { } } +} + FieldSearchSpec::FieldSearchSpec() : _id(0), _name(), @@ -205,6 +209,36 @@ void FieldSearchSpecMap::buildFromConfig(const std::vector & o } } +namespace { + +FieldIdTList +buildFieldSet(const VsmfieldsConfig::Documenttype::Index & ci, const FieldSearchSpecMapT & specMap, + 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()) { + FieldIdTList sub = buildFieldSet(*foundIndex, specMap, indexes); + ifm.insert(ifm.end(), sub.begin(), sub.end()); + } else { + auto foundField = std::find_if(specMap.begin(), specMap.end(), + [&cf](const auto & v) { return v.second.name() == cf.name;} ); + if (foundField != specMap.end()) { + ifm.push_back(foundField->second.id()); + } else { + LOG(warning, "Field %s not defined. Ignoring....", cf.name.c_str()); + } + } + } + return ifm; +} + +} + bool FieldSearchSpecMap::buildFromConfig(const VsmfieldsHandle & conf) { bool retval(true); @@ -223,19 +257,7 @@ bool FieldSearchSpecMap::buildFromConfig(const VsmfieldsHandle & conf) IndexFieldMapT indexMapp; LOG(spam, "Parsing document type %s with %zd indexes", di.name.c_str(), di.index.size()); for(const VsmfieldsConfig::Documenttype::Index & ci : di.index) { - 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()); - FieldSearchSpecMapT::const_iterator fIt, mIt; - for (fIt=specMap().begin(), mIt=specMap().end(); (fIt != mIt) && (fIt->second.name() != cf.name); fIt++); - if (fIt != mIt) { - ifm.push_back(fIt->second.id()); - } else { - LOG(warning, "Field %s not defined. Ignoring....", cf.name.c_str()); - } - } - indexMapp[ci.name] = ifm; + indexMapp[ci.name] = buildFieldSet(ci, specMap(), di.index); } _documentTypeMap[di.name] = indexMapp; } -- cgit v1.2.3