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 {
3433namespace {
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-
6447bool 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
7657filter::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-
365337bool Not::equals (const irs::filter& rhs) const noexcept {
366338 if (!filter::equals (rhs)) {
367339 return false ;
0 commit comments