Skip to content

Commit

Permalink
Merge pull request #33016 from vespa-engine/toregge/nearest-neighbor-…
Browse files Browse the repository at this point in the history
…term-operator-needs-ranking

Nearest neighbor term operator needs ranking.
  • Loading branch information
geirst authored Dec 9, 2024
2 parents 7db3d8d + 4a8b626 commit 3465fd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions searchcore/src/tests/proton/matching/query_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,13 @@ TEST(QueryTest, wand_term_needs_ranking)
EXPECT_TRUE(query_needs_ranking(StackDumpCreator::create(*builder.build())));
}

TEST(QueryTest, nearest_neighbor_term_needs_ranking)
{
QueryBuilder<ProtonNodeTypes> builder;
builder.add_nearest_neighbor_term("qtensor", "f1", 1, Weight(1), 10, true, 100, 1.5);
EXPECT_TRUE(query_needs_ranking(StackDumpCreator::create(*builder.build())));
}

} // namespace
} // namespace proton::matching

Expand Down
5 changes: 3 additions & 2 deletions searchcore/src/vespa/searchcore/proton/matching/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void exchange_location_nodes(const string &location_str,
}

/*
* WeakAnd, WeightedSetTerm, DotProduct and WandTerm query operators need ranking since
* doUnpack is used to updated threshold during query evaluation.
* WeakAnd, WandTerm and NearestNeighborTerm query operators need ranking since
* doUnpack is used to update threshold during query evaluation.
*/
class NeedsRankingVisitor : public TemplateTermVisitor<NeedsRankingVisitor, ProtonNodeTypes>
{
Expand All @@ -159,6 +159,7 @@ class NeedsRankingVisitor : public TemplateTermVisitor<NeedsRankingVisitor, Prot
template <class TermNode> void visitTerm(TermNode&) { }
void visit(ProtonNodeTypes::WeakAnd&) override { _needs_ranking = true; }
void visitTerm(ProtonNodeTypes::WandTerm&) { _needs_ranking = true; }
void visitTerm(ProtonNodeTypes::NearestNeighborTerm&) { _needs_ranking = true; }
bool needs_ranking() const noexcept { return _needs_ranking; }
};

Expand Down

0 comments on commit 3465fd9

Please sign in to comment.