Skip to content

Commit

Permalink
Merge pull request #32656 from vespa-engine/havardpe/allow-at-least-o…
Browse files Browse the repository at this point in the history
…ne-of-each-type

allow at least one of each category
  • Loading branch information
hmusum authored Oct 24, 2024
2 parents f5473ef + 6e5f359 commit e8530ee
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ TEST("require that max group size is calculated correctly") {
for (size_t min_groups: std::vector<size_t>({0, 1, 2, 3, 4, 10, 500})) {
for (size_t wanted_hits: std::vector<size_t>({0, 3, 321, 921})) {
MatchPhaseLimitCalculator calc(100, min_groups, 0.2);
if (min_groups == 0) {
if (wanted_hits <= min_groups) {
EXPECT_EQUAL(size_t(1), calc.max_group_size(wanted_hits));
} else if (min_groups == 0) {
EXPECT_EQUAL(wanted_hits, calc.max_group_size(wanted_hits));
} else {
EXPECT_EQUAL((wanted_hits / min_groups), calc.max_group_size(wanted_hits));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class MatchPhaseLimitCalculator
size_t estimated_hits(double hit_rate, size_t num_docs) const noexcept {
return (size_t) (hit_rate * num_docs);
}
size_t max_group_size(size_t wanted_num_docs_in) const noexcept {
return (wanted_num_docs_in / _min_groups);
size_t max_group_size(size_t wanted_num_docs) const noexcept {
return std::max(size_t(1), wanted_num_docs / _min_groups);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ MatchToolsFactory::createDiversifier(uint32_t heapSize) const
Issue::report("Skipping diversity due to no %s attribute.", _diversityParams.attribute.c_str());
return {};
}
size_t max_per_group = heapSize/_diversityParams.min_groups;
size_t max_per_group = std::max(size_t(1), size_t(heapSize / _diversityParams.min_groups));
return DiversityFilter::create(*attr, heapSize, max_per_group, _diversityParams.min_groups,
_diversityParams.cutoff_strategy == DiversityParams::CutoffStrategy::STRICT);
}
Expand Down
2 changes: 1 addition & 1 deletion searchlib/src/vespa/searchlib/attribute/diversity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DiversityFilterT<Fetcher>::accepted(uint32_t docId) {

std::unique_ptr<DiversityFilter>
DiversityFilter::create(const IAttributeVector &diversity_attr, size_t wanted_hits,
size_t max_per_group,size_t cutoff_max_groups, bool cutoff_strict)
size_t max_per_group, size_t cutoff_max_groups, bool cutoff_strict)
{
if (diversity_attr.hasEnum()) { // must handle enum first
FetchEnumFast fastEnum(diversity_attr);
Expand Down
2 changes: 1 addition & 1 deletion searchlib/src/vespa/searchlib/attribute/diversity.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DiversityFilter : public queryeval::IDiversifier {
size_t getMaxTotal() const { return _max_total; }
static std::unique_ptr<DiversityFilter>
create(const IAttributeVector &diversity_attr, size_t wanted_hits,
size_t max_per_group,size_t cutoff_max_groups, bool cutoff_strict);
size_t max_per_group, size_t cutoff_max_groups, bool cutoff_strict);
protected:
size_t _max_total;
};
Expand Down

0 comments on commit e8530ee

Please sign in to comment.