Skip to content

Commit cfcaa24

Browse files
Merge branch 'iresearch-toolkit:master' into master
2 parents 2fafdc4 + df481fa commit cfcaa24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+435
-670
lines changed

core/analysis/analyzers.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ struct value {
6565

6666
} // namespace
6767

68-
namespace std {
69-
7068
template<>
71-
struct hash<::key> {
69+
struct std::hash<::key> {
7270
size_t operator()(const ::key& value) const noexcept {
7371
return irs::hash_combine(
7472
std::hash<irs::type_info::type_id>()(value.args_format.id()), value.type);
7573
}
7674
};
7775

78-
} // namespace std
7976
namespace irs::analysis {
8077
namespace {
8178

core/analysis/pipeline_token_stream.hpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,15 @@ class pipeline_token_stream final : public TypedAnalyzer<pipeline_token_stream>,
7070
template<typename Visitor>
7171
bool visit_members(Visitor&& visitor) const {
7272
for (const auto& sub : pipeline_) {
73-
if (sub.get_stream().type() ==
74-
type()) { // pipe inside pipe - forward visiting
75-
#if IRESEARCH_DEBUG
76-
const auto& sub_pipe =
77-
dynamic_cast<const pipeline_token_stream&>(sub.get_stream());
78-
#else
79-
const auto& sub_pipe =
80-
static_cast<const pipeline_token_stream&>(sub.get_stream());
81-
#endif
73+
const auto& stream = sub.get_stream();
74+
if (stream.type() == type()) {
75+
// pipe inside pipe - forward visiting
76+
const auto& sub_pipe = DownCast<pipeline_token_stream>(stream);
8277
if (!sub_pipe.visit_members(visitor)) {
8378
return false;
8479
}
85-
} else {
86-
if (!visitor(sub.get_stream())) {
87-
return false;
88-
}
80+
} else if (!visitor(sub.get_stream())) {
81+
return false;
8982
}
9083
}
9184
return true;

core/search/all_docs_provider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace irs {
2828

29-
filter::ptr AllDocsProvider::Default(score_t boost) {
29+
AllDocsProvider::Ptr AllDocsProvider::Default(score_t boost) {
3030
auto filter = std::make_unique<all>();
3131
filter->boost(boost);
3232
return filter;

core/search/all_docs_provider.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ namespace irs {
2828

2929
class AllDocsProvider {
3030
public:
31-
using ProviderFunc = std::function<filter::ptr(score_t)>;
31+
using Ptr = std::unique_ptr<FilterWithBoost>;
32+
using ProviderFunc = std::function<Ptr(score_t)>;
3233

33-
static filter::ptr Default(score_t boost);
34+
static Ptr Default(score_t boost);
3435

35-
filter::ptr MakeAllDocsFilter(score_t boost) const {
36-
return all_docs_(boost);
37-
}
36+
Ptr MakeAllDocsFilter(score_t boost) const { return all_docs_(boost); }
3837

3938
void SetProvider(ProviderFunc&& provider) {
4039
all_docs_ = provider ? std::move(provider) : ProviderFunc{&Default};

core/search/all_filter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@ namespace irs {
3030
class all_query : public filter::prepared {
3131
public:
3232
explicit all_query(bstring&& stats, score_t boost)
33-
: filter::prepared(boost), stats_(std::move(stats)) {}
33+
: stats_{std::move(stats)}, boost_{boost} {}
3434

3535
doc_iterator::ptr execute(const ExecutionContext& ctx) const final {
3636
auto& rdr = ctx.segment;
3737

3838
return memory::make_managed<AllIterator>(rdr, stats_.c_str(), ctx.scorers,
39-
rdr.docs_count(), boost());
39+
rdr.docs_count(), boost_);
4040
}
4141

4242
void visit(const SubReader&, PreparedStateVisitor&, score_t) const final {
4343
// No terms to visit
4444
}
4545

46+
score_t boost() const noexcept final { return boost_; }
47+
4648
private:
4749
bstring stats_;
50+
score_t boost_;
4851
};
4952

5053
filter::prepared::ptr all::prepare(const PrepareContext& ctx) const {

core/search/all_filter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
namespace irs {
2828

2929
// Filter returning all documents
30-
class all : public filter {
30+
class all : public FilterWithBoost {
3131
public:
32-
filter::prepared::ptr prepare(const PrepareContext& ctx) const final;
32+
prepared::ptr prepare(const PrepareContext& ctx) const final;
3333

3434
irs::type_info::type_id type() const noexcept final {
3535
return irs::type<all>::id();

core/search/boolean_filter.cpp

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,36 @@
2222

2323
#include "boolean_filter.hpp"
2424

25-
#include <boost/container_hash/hash.hpp>
26-
2725
#include "conjunction.hpp"
2826
#include "disjunction.hpp"
2927
#include "exclusion.hpp"
3028
#include "min_match_disjunction.hpp"
3129
#include "prepared_state_visitor.hpp"
3230
#include "search/boolean_query.hpp"
3331

32+
namespace irs {
3433
namespace {
3534

36-
// first - pointer to the innermost not "not" node
37-
// second - collapsed negation mark
38-
std::pair<const irs::filter*, bool> optimize_not(const irs::Not& node) {
35+
std::pair<const filter*, bool> optimize_not(const Not& node) {
3936
bool neg = true;
40-
const irs::filter* inner = node.filter();
41-
while (inner && inner->type() == irs::type<irs::Not>::id()) {
37+
const auto* inner = node.filter();
38+
while (inner != nullptr && inner->type() == type<Not>::id()) {
4239
neg = !neg;
43-
inner = static_cast<const irs::Not*>(inner)->filter();
40+
inner = DownCast<Not>(inner)->filter();
4441
}
4542

46-
return std::make_pair(inner, neg);
43+
return std::pair{inner, neg};
4744
}
4845

4946
} // namespace
50-
51-
namespace irs {
52-
53-
size_t boolean_filter::hash() const noexcept {
54-
size_t seed = 0;
55-
56-
::boost::hash_combine(seed, filter::hash());
57-
std::for_each(
58-
filters_.begin(), filters_.end(),
59-
[&seed](const filter::ptr& f) { ::boost::hash_combine(seed, *f); });
60-
61-
return seed;
62-
}
63-
6447
bool boolean_filter::equals(const filter& rhs) const noexcept {
6548
if (!filter::equals(rhs)) {
6649
return false;
6750
}
6851
const auto& typed_rhs = DownCast<boolean_filter>(rhs);
69-
return filters_.size() == typed_rhs.size() &&
70-
std::equal(begin(), end(), typed_rhs.begin(),
71-
[](const filter::ptr& lhs, const filter::ptr& rhs) {
72-
return *lhs == *rhs;
73-
});
52+
return std::equal(
53+
begin(), end(), typed_rhs.begin(), typed_rhs.end(),
54+
[](const auto& lhs, const auto& rhs) { return *lhs == *rhs; });
7455
}
7556

7657
filter::prepared::ptr boolean_filter::prepare(const PrepareContext& ctx) const {
@@ -94,8 +75,8 @@ filter::prepared::ptr boolean_filter::prepare(const PrepareContext& ctx) const {
9475
std::vector<const filter*> incl;
9576
std::vector<const filter*> excl;
9677

97-
irs::filter::ptr all_docs_zero_boost;
98-
irs::filter::ptr all_docs_no_boost;
78+
AllDocsProvider::Ptr all_docs_zero_boost;
79+
AllDocsProvider::Ptr all_docs_no_boost;
9980

10081
group_filters(all_docs_zero_boost, incl, excl);
10182

@@ -108,29 +89,29 @@ filter::prepared::ptr boolean_filter::prepare(const PrepareContext& ctx) const {
10889
return PrepareBoolean(incl, excl, ctx);
10990
}
11091

111-
void boolean_filter::group_filters(filter::ptr& all_docs_zero_boost,
92+
void boolean_filter::group_filters(AllDocsProvider::Ptr& all_docs_zero_boost,
11293
std::vector<const filter*>& incl,
11394
std::vector<const filter*>& excl) const {
11495
incl.reserve(size() / 2);
11596
excl.reserve(incl.capacity());
11697

117-
const irs::filter* empty_filter{nullptr};
98+
const filter* empty_filter = nullptr;
11899
const auto is_or = type() == irs::type<Or>::id();
119-
for (auto begin = this->begin(), end = this->end(); begin != end; ++begin) {
120-
if (irs::type<irs::empty>::id() == (*begin)->type()) {
121-
empty_filter = begin->get();
100+
for (const auto& filter : *this) {
101+
if (irs::type<Empty>::id() == filter->type()) {
102+
empty_filter = filter.get();
122103
continue;
123104
}
124-
if (irs::type<Not>::id() == (*begin)->type()) {
125-
const auto res = optimize_not(DownCast<Not>(**begin));
105+
if (irs::type<Not>::id() == filter->type()) {
106+
const auto res = optimize_not(DownCast<Not>(*filter));
126107

127108
if (!res.first) {
128109
continue;
129110
}
130111

131112
if (res.second) {
132113
if (!all_docs_zero_boost) {
133-
all_docs_zero_boost = MakeAllDocsFilter(0.f);
114+
all_docs_zero_boost = MakeAllDocsFilter(0.F);
134115
}
135116

136117
if (*all_docs_zero_boost == *res.first) {
@@ -148,7 +129,7 @@ void boolean_filter::group_filters(filter::ptr& all_docs_zero_boost,
148129
incl.push_back(res.first);
149130
}
150131
} else {
151-
incl.push_back(begin->get());
132+
incl.push_back(filter.get());
152133
}
153134
}
154135
if (empty_filter != nullptr) {
@@ -162,7 +143,7 @@ filter::prepared::ptr And::PrepareBoolean(std::vector<const filter*>& incl,
162143
// optimization step
163144
// if include group empty itself or has 'empty' -> this whole conjunction is
164145
// empty
165-
if (incl.empty() || incl.back()->type() == irs::type<irs::empty>::id()) {
146+
if (incl.empty() || incl.back()->type() == irs::type<Empty>::id()) {
166147
return prepared::empty();
167148
}
168149

@@ -180,7 +161,7 @@ filter::prepared::ptr And::PrepareBoolean(std::vector<const filter*>& incl,
180161
for (auto filter : incl) {
181162
if (*filter == *cumulative_all) {
182163
all_count++;
183-
all_boost += filter->boost();
164+
all_boost += DownCast<FilterWithBoost>(*filter).boost();
184165
}
185166
}
186167
if (all_count != 0) {
@@ -204,7 +185,7 @@ filter::prepared::ptr And::PrepareBoolean(std::vector<const filter*>& incl,
204185
// resulting boost will be: new_boost * OR_BOOST * LEFT_BOOST. If we
205186
// substitute new_boost back we will get ( boost * OR_BOOST * ALL_BOOST +
206187
// boost * OR_BOOST * LEFT_BOOST) - original non-optimized boost value
207-
auto left_boost = (*incl.begin())->boost();
188+
auto left_boost = (*incl.begin())->BoostImpl();
208189
if (boost() != 0 && left_boost != 0 && !sub_ctx.scorers.empty()) {
209190
sub_ctx.boost = (sub_ctx.boost * boost() * all_boost +
210191
sub_ctx.boost * boost() * left_boost) /
@@ -247,7 +228,7 @@ filter::prepared::ptr Or::PrepareBoolean(std::vector<const filter*>& incl,
247228
return MakeAllDocsFilter(kNoBoost)->prepare(sub_ctx);
248229
}
249230

250-
if (!incl.empty() && incl.back()->type() == irs::type<irs::empty>::id()) {
231+
if (!incl.empty() && incl.back()->type() == irs::type<Empty>::id()) {
251232
incl.pop_back();
252233
}
253234

@@ -270,7 +251,7 @@ filter::prepared::ptr Or::PrepareBoolean(std::vector<const filter*>& incl,
270251
for (auto filter : incl) {
271252
if (*filter == *cumulative_all) {
272253
all_count++;
273-
all_boost += filter->boost();
254+
all_boost += DownCast<FilterWithBoost>(*filter).boost();
274255
incl_all = filter;
275256
}
276257
}
@@ -353,15 +334,6 @@ filter::prepared::ptr Not::prepare(const PrepareContext& ctx) const {
353334
return res.first->prepare(sub_ctx);
354335
}
355336

356-
size_t Not::hash() const noexcept {
357-
size_t seed = 0;
358-
::boost::hash_combine(seed, filter::hash());
359-
if (filter_) {
360-
::boost::hash_combine<const irs::filter&>(seed, *filter_);
361-
}
362-
return seed;
363-
}
364-
365337
bool Not::equals(const irs::filter& rhs) const noexcept {
366338
if (!filter::equals(rhs)) {
367339
return false;

0 commit comments

Comments
 (0)