zzzxl1993 commented on code in PR #56329:
URL: https://github.com/apache/doris/pull/56329#discussion_r2370982351
##########
be/src/olap/rowset/segment_v2/inverted_index/query_v2/boolean_query/boolean_weight.h:
##########
@@ -37,20 +37,62 @@ class BooleanWeight : public Weight {
~BooleanWeight() override = default;
ScorerPtr scorer(const CompositeReaderPtr& composite_reader) override {
- std::vector<ScorerPtr> sub_scorers = per_scorers(composite_reader);
if (_type == OperatorType::OP_AND) {
- return intersection_scorer_build(sub_scorers);
- } else if (_type == OperatorType::OP_OR) {
+ std::vector<ScorerPtr> include_scorers;
+ std::vector<ScorerPtr> exclude_scorers;
+ include_scorers.reserve(_sub_weights.size());
+ exclude_scorers.reserve(_sub_weights.size());
+
+ for (const auto& sub_weight : _sub_weights) {
+ auto boolean_weight =
+
std::dynamic_pointer_cast<BooleanWeight<ScoreCombinerPtrT>>(sub_weight);
+ if (boolean_weight != nullptr && boolean_weight->_type ==
OperatorType::OP_NOT) {
+ auto exclude = boolean_weight->scorer(composite_reader);
+ if (exclude != nullptr) {
+ exclude_scorers.emplace_back(std::move(exclude));
+ }
+ continue;
+ }
+
+ auto scorer = sub_weight->scorer(composite_reader);
+ if (scorer != nullptr) {
+ include_scorers.emplace_back(std::move(scorer));
+ }
+ }
+
+ if (include_scorers.empty()) {
+ return std::make_shared<EmptyScorer>();
+ }
+
+ auto intersection = intersection_scorer_build(include_scorers);
+ if (exclude_scorers.empty()) {
+ return intersection;
+ }
+
+ return std::make_shared<AndNotScorer>(std::move(intersection),
+ std::move(exclude_scorers));
+ }
+
+ std::vector<ScorerPtr> sub_scorers = per_scorers(composite_reader);
+ if (_type == OperatorType::OP_OR || _type == OperatorType::OP_NOT) {
Review Comment:
search(text:a or not text:b)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]