Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Fix boost compute
Browse files Browse the repository at this point in the history
  • Loading branch information
MBkkt committed Aug 3, 2023
1 parent 336276c commit 57c9a92
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
3 changes: 1 addition & 2 deletions core/search/all_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ filter::prepared::ptr all::prepare(const PrepareContext& ctx) const {

PrepareCollectors(ctx.scorers.buckets(), stats_buf);

return memory::make_managed<all_query>(std::move(stats),
this->boost() * ctx.boost);
return memory::make_managed<all_query>(std::move(stats), ctx.boost * boost());
}

} // namespace irs
45 changes: 18 additions & 27 deletions core/search/boolean_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,19 @@ filter::prepared::ptr boolean_filter::prepare(const PrepareContext& ctx) const {
return prepared::empty();
}

const PrepareContext sub_ctx{
.index = ctx.index,
.memory = ctx.memory,
.scorers = ctx.scorers,
.ctx = ctx.ctx,
.boost = ctx.boost * boost(),
};

if (size == 1) {
auto* filter = filters_.front().get();
IRS_ASSERT(filter);

// FIXME(gnusi): let Not handle everything?
if (filter->type() != irs::type<irs::Not>::id()) {
return filter->prepare(sub_ctx);
return filter->prepare({
.index = ctx.index,
.memory = ctx.memory,
.scorers = ctx.scorers,
.ctx = ctx.ctx,
.boost = ctx.boost * boost(),
});
}
}

Expand All @@ -370,7 +368,7 @@ filter::prepared::ptr boolean_filter::prepare(const PrepareContext& ctx) const {
incl.push_back(all_docs_no_boost.get());
}

return PrepareBoolean(incl, excl, sub_ctx);
return PrepareBoolean(incl, excl, ctx);
}

void boolean_filter::group_filters(filter::ptr& all_docs_zero_boost,
Expand Down Expand Up @@ -431,16 +429,11 @@ filter::prepared::ptr And::PrepareBoolean(std::vector<const filter*>& incl,
return prepared::empty();
}

PrepareContext sub_ctx{
.index = ctx.index,
.memory = ctx.memory,
.scorers = ctx.scorers,
.ctx = ctx.ctx,
.boost = ctx.boost * boost(),
};
PrepareContext sub_ctx = ctx;

// single node case
if (1 == incl.size() && excl.empty()) {
sub_ctx.boost *= boost();
return incl.front()->prepare(sub_ctx);
}

Expand Down Expand Up @@ -499,20 +492,18 @@ filter::prepared::ptr And::PrepareBoolean(std::vector<const filter*>& incl,
}

filter::prepared::ptr Or::prepare(const PrepareContext& ctx) const {
const PrepareContext sub_ctx{
.index = ctx.index,
.memory = ctx.memory,
.scorers = ctx.scorers,
.ctx = ctx.ctx,
.boost = ctx.boost * boost(),
};

if (0 == min_match_count_) { // only explicit 0 min match counts!
// all conditions are satisfied
return MakeAllDocsFilter(kNoBoost)->prepare(sub_ctx);
return MakeAllDocsFilter(kNoBoost)->prepare({
.index = ctx.index,
.memory = ctx.memory,
.scorers = ctx.scorers,
.ctx = ctx.ctx,
.boost = ctx.boost * boost(),
});
}

return boolean_filter::prepare(sub_ctx);
return boolean_filter::prepare(ctx);
}

filter::prepared::ptr Or::PrepareBoolean(std::vector<const filter*>& incl,
Expand Down
4 changes: 2 additions & 2 deletions core/search/phrase_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ filter::prepared::ptr by_phrase::fixed_prepare_collect(const IndexReader& index,

return memory::make_managed<FixedPhraseQuery>(
std::move(phrase_states), std::move(positions), std::move(stats),
this->boost() * boost);
boost * this->boost());
}

filter::prepared::ptr by_phrase::variadic_prepare_collect(
Expand Down Expand Up @@ -424,7 +424,7 @@ filter::prepared::ptr by_phrase::variadic_prepare_collect(

return memory::make_managed<VariadicPhraseQuery>(
std::move(phrase_states), std::move(positions), std::move(stats),
this->boost() * boost);
boost * this->boost());
}

} // namespace irs
2 changes: 1 addition & 1 deletion core/search/wildcard_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class by_wildcard final : public filter_base<by_wildcard_options> {
static field_visitor visitor(bytes_view term);

filter::prepared::ptr prepare(const PrepareContext& ctx) const final {
return prepare(ctx.index, ctx.scorers, this->boost() * ctx.boost, field(),
return prepare(ctx.index, ctx.scorers, ctx.boost * boost(), field(),
options().term, options().scored_terms_limit);
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/search/boolean_filter_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ struct boosted : public irs::filter {

irs::filter::prepared::ptr prepare(
const irs::PrepareContext& ctx) const final {
return irs::memory::make_managed<boosted::prepared>(
docs, this->boost() * ctx.boost);
return irs::memory::make_managed<boosted::prepared>(docs,
ctx.boost * boost());
}

irs::type_info::type_id type() const noexcept final {
Expand Down

0 comments on commit 57c9a92

Please sign in to comment.