diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-11-05 08:36:55 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-11-05 08:36:55 +0000 |
commit | d5f3e331c8cf559c7acffa45f70982907d677da9 (patch) | |
tree | d15f3fc5f7803cb9d15566bcc969ee0dbd3680a8 | |
parent | 4148246c837f232e63408ac10927cd5c2efa6a59 (diff) |
Add new maxWeight output to the attributeMatch rank feature.
3 files changed, 22 insertions, 4 deletions
diff --git a/searchlib/src/tests/features/prod_features_attributematch.cpp b/searchlib/src/tests/features/prod_features_attributematch.cpp index e5d37e62bee..3f6031bedce 100644 --- a/searchlib/src/tests/features/prod_features_attributematch.cpp +++ b/searchlib/src/tests/features/prod_features_attributematch.cpp @@ -49,7 +49,8 @@ Test::testAttributeMatch() .add("importance") .add("matches") .add("totalWeight") - .add("averageWeight")); + .add("averageWeight") + .add("maxWeight")); FT_DUMP_EMPTY(_factory, "attributeMatch"); @@ -65,7 +66,8 @@ Test::testAttributeMatch() .add("attributeMatch(sint).importance") .add("attributeMatch(sint).matches") .add("attributeMatch(sint).totalWeight") - .add("attributeMatch(sint).averageWeight")); + .add("attributeMatch(sint).averageWeight") + .add("attributeMatch(sint).maxWeight")); } { // single attributes @@ -108,6 +110,7 @@ Test::testAttributeMatch() addScore("attributeMatch(sint).matches", 2). addScore("attributeMatch(sint).totalWeight", 0). addScore("attributeMatch(sint).averageWeight", 0). + addScore("attributeMatch(sint).maxWeight", 0). addScore("attributeMatch(sint).completeness", 0.5f). addScore("attributeMatch(sint).queryCompleteness", 0.5f). addScore("attributeMatch(sint).fieldCompleteness", 1). @@ -120,6 +123,7 @@ Test::testAttributeMatch() addScore("attributeMatch(sfloat).matches", 1). addScore("attributeMatch(sfloat).totalWeight", 0). addScore("attributeMatch(sfloat).averageWeight", 0). + addScore("attributeMatch(sfloat).maxWeight", 0). addScore("attributeMatch(sfloat).completeness", 1). addScore("attributeMatch(sfloat).queryCompleteness", 1). addScore("attributeMatch(sfloat).fieldCompleteness", 1). @@ -132,6 +136,7 @@ Test::testAttributeMatch() addScore("attributeMatch(sstr).matches", 0). addScore("attributeMatch(sstr).totalWeight", 0). addScore("attributeMatch(sstr).averageWeight", 0). + addScore("attributeMatch(sstr).maxWeight", 0). addScore("attributeMatch(sstr).completeness", 0). addScore("attributeMatch(sstr).queryCompleteness", 0). addScore("attributeMatch(sstr).fieldCompleteness", 0). @@ -162,6 +167,7 @@ Test::testAttributeMatch() .addScore("attributeMatch(aint).matches", 1) .addScore("attributeMatch(aint).totalWeight", 0) .addScore("attributeMatch(aint).averageWeight", 0) + .addScore("attributeMatch(aint).maxWeight", 0) .addScore("attributeMatch(aint).completeness", 0.75f) .addScore("attributeMatch(aint).queryCompleteness", 1) .addScore("attributeMatch(aint).fieldCompleteness", 0.5f) @@ -202,6 +208,7 @@ Test::testAttributeMatch() addScore("attributeMatch(wsint).matches", 2). addScore("attributeMatch(wsint).totalWeight", 30). addScore("attributeMatch(wsint).averageWeight", 15). + addScore("attributeMatch(wsint).maxWeight", 20). addScore("attributeMatch(wsint).completeness", 1). addScore("attributeMatch(wsint).queryCompleteness", 1). addScore("attributeMatch(wsint).fieldCompleteness", 1). @@ -211,6 +218,7 @@ Test::testAttributeMatch() addScore("attributeMatch(wsfloat).matches", 1). addScore("attributeMatch(wsfloat).totalWeight", -30). addScore("attributeMatch(wsfloat).averageWeight", -30). + addScore("attributeMatch(wsfloat).maxWeight", -30). addScore("attributeMatch(wsfloat).completeness", 0.95). addScore("attributeMatch(wsfloat).queryCompleteness", 1). addScore("attributeMatch(wsfloat).fieldCompleteness", 0). @@ -220,6 +228,7 @@ Test::testAttributeMatch() addScore("attributeMatch(wsstr).matches", 0). addScore("attributeMatch(wsstr).totalWeight", 0). addScore("attributeMatch(wsstr).averageWeight", 0). + addScore("attributeMatch(wsstr).maxWeight", 0). addScore("attributeMatch(wsstr).completeness", 0). addScore("attributeMatch(wsstr).queryCompleteness", 0). addScore("attributeMatch(wsstr).fieldCompleteness", 0). @@ -267,6 +276,7 @@ Test::testAttributeMatch() addScore("attributeMatch(unique).matches", 0). addScore("attributeMatch(unique).totalWeight", 0). addScore("attributeMatch(unique).averageWeight", 0). + addScore("attributeMatch(unique).maxWeight", 0). addScore("attributeMatch(unique).completeness", 0). addScore("attributeMatch(unique).queryCompleteness", 0). addScore("attributeMatch(unique).fieldCompleteness", 0). diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp index 27c7b77ec26..ff4ca91beb9 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp @@ -54,6 +54,7 @@ AttributeMatchExecutor<T>::Computer::Computer(const IQueryEnvironment & env, Att _matchedTermWeight(0), _matchedTermSignificance(0), _totalWeight(0), + _maxWeight(0), _normalizedWeightedWeight(0), _weightSum(0), _valueCount(0), @@ -89,6 +90,7 @@ AttributeMatchExecutor<T>::Computer::reset() _matchedTermWeight = 0, _matchedTermSignificance = 0, _totalWeight = 0; + _maxWeight = 0; _normalizedWeightedWeight = 0; _weightSum = 0; _valueCount = 0; @@ -109,6 +111,7 @@ AttributeMatchExecutor<T>::Computer::run(uint32_t docId) if (_params.weightedSet) { int32_t weight = tfmd->getWeight(); _totalWeight += weight; + _maxWeight = (_matches == 1) ? weight : std::max(_maxWeight, weight); // attribute weight * query term weight _normalizedWeightedWeight += weight * static_cast<int32_t>(td->getWeight().percent()); } @@ -123,9 +126,9 @@ AttributeMatchExecutor<T>::Computer::run(uint32_t docId) _valueCount = _params.attribute->getValueCount(docId); } - LOG(debug, "attributeMatch(%s)::Computer::run(): matches(%u), totalWeight(%d), normalizedWeightedWeight(%f), " + LOG(debug, "attributeMatch(%s)::Computer::run(): matches(%u), totalWeight(%d), maxWeight(%d), normalizedWeightedWeight(%f), " "weightSum(%d), valueCount(%u), matchedTermWeight(%u), matchedTermSignificance(%f)", - _params.attrInfo->name().c_str(), _matches, _totalWeight, _normalizedWeightedWeight, + _params.attrInfo->name().c_str(), _matches, _totalWeight, _maxWeight, _normalizedWeightedWeight, _weightSum, _valueCount, _matchedTermWeight, _matchedTermSignificance); } @@ -250,6 +253,7 @@ AttributeMatchExecutor<T>::execute(uint32_t docId) outputs().set_number(8, static_cast<feature_t>(_cmp.getMatches())); outputs().set_number(9, static_cast<feature_t>(_cmp.getTotalWeight())); outputs().set_number(10, _cmp.getAverageWeight()); + outputs().set_number(11, static_cast<feature_t>(_cmp.getMaxWeight())); } template <typename T> @@ -288,6 +292,7 @@ AttributeMatchBlueprint::visitDumpFeatures(const IIndexEnvironment &env, visitor.visitDumpFeature(fnb.output("matches").buildName()); visitor.visitDumpFeature(fnb.output("totalWeight").buildName()); visitor.visitDumpFeature(fnb.output("averageWeight").buildName()); + visitor.visitDumpFeature(fnb.output("maxWeight").buildName()); } } } @@ -323,6 +328,7 @@ AttributeMatchBlueprint::setup(const IIndexEnvironment & env, describeOutput("matches", "The number of query terms which was matched in this attribute"); describeOutput("totalWeight", "The sum of the weights of the attribute keys matched in a weighted set attribute"); describeOutput("averageWeight", "totalWeight/matches"); + describeOutput("maxWeight", "The max weight of the attribute keys matched in a weighted set attribute"); env.hintAttributeAccess(_params.attrInfo->name()); return true; diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.h b/searchlib/src/vespa/searchlib/features/attributematchfeature.h index 487a35ab573..2946521c9f0 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.h +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.h @@ -45,6 +45,7 @@ private: uint32_t _matchedTermWeight; // term weight of matched terms feature_t _matchedTermSignificance; // significance of matched terms int32_t _totalWeight; + int32_t _maxWeight; feature_t _normalizedWeightedWeight; int32_t _weightSum; // sum of the weights for a weighted set attribute uint32_t _valueCount; // the number of values for a non-weighted set attribute @@ -57,6 +58,7 @@ private: uint32_t getNumTerms() const { return _queryTerms.size(); } uint32_t getMatches() const { return _matches; } int32_t getTotalWeight() const { return _totalWeight; } + int32_t getMaxWeight() const { return _maxWeight; } feature_t getAverageWeight() const; feature_t getQueryCompleteness() const; feature_t getNormalizedWeight() const; |