Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions be/src/olap/collection_statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class CollectionStatistics {

MOCK_DEFINE(friend class BM25SimilarityTest;)
MOCK_DEFINE(friend class CollectionStatisticsTest;)
MOCK_DEFINE(friend class BooleanQueryTest;)
};
using CollectionStatisticsPtr = std::shared_ptr<CollectionStatistics>;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include "olap/rowset/segment_v2/inverted_index/query_v2/boolean_query/boolean_weight.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/operator.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/query.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/score_combiner.h"

namespace doris::segment_v2::inverted_index::query_v2 {

class BooleanQuery;
using BooleanQueryPtr = std::shared_ptr<BooleanQuery>;

class BooleanQuery : public Query {
public:
BooleanQuery(OperatorType type, std::vector<QueryPtr> clauses)
: _type(type), _sub_queries(std::move(clauses)) {}
~BooleanQuery() override = default;

WeightPtr weight(bool enable_scoring) override {
std::vector<WeightPtr> sub_weights;
for (const auto& query : _sub_queries) {
sub_weights.emplace_back(query->weight(enable_scoring));
}
if (enable_scoring) {
return std::make_shared<BooleanWeight<SumCombinerPtr>>(_type, std::move(sub_weights),
std::make_shared<SumCombiner>());
} else {
return std::make_shared<BooleanWeight<DoNothingCombinerPtr>>(
_type, std::move(sub_weights), std::make_shared<DoNothingCombiner>());
}
}

class Builder {
public:
Builder(OperatorType type) : _type(type) {}
~Builder() = default;

void add(const QueryPtr& query) { _sub_queries.emplace_back(query); }

BooleanQueryPtr build() {
return std::make_shared<BooleanQuery>(_type, std::move(_sub_queries));
}

private:
OperatorType _type;
std::vector<QueryPtr> _sub_queries;
};

private:
OperatorType _type;
std::vector<QueryPtr> _sub_queries;
};

} // namespace doris::segment_v2::inverted_index::query_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <vector>

#include "olap/rowset/segment_v2/inverted_index/query_v2/buffered_union_scorer.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/intersection_scorer.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/operator.h"
#include "olap/rowset/segment_v2/inverted_index/query_v2/weight.h"

namespace doris::segment_v2::inverted_index::query_v2 {

template <typename ScoreCombinerPtrT>
class BooleanWeight : public Weight {
public:
BooleanWeight(OperatorType type, std::vector<WeightPtr> sub_weights,
ScoreCombinerPtrT score_combiner)
: _type(type),
_sub_weights(std::move(sub_weights)),
_score_combiner(std::move(score_combiner)) {}
~BooleanWeight() override = default;

ScorerPtr scorer(lucene::index::IndexReader* reader) override {
std::vector<ScorerPtr> sub_scorers = per_scorers(reader);
if (_type == OperatorType::OP_AND) {
return intersection_scorer_build(sub_scorers);
} else if (_type == OperatorType::OP_OR) {
return buffered_union_scorer_build<ScoreCombinerPtrT>(sub_scorers, _score_combiner);
}
return nullptr;
}

private:
std::vector<ScorerPtr> per_scorers(lucene::index::IndexReader* reader) {
std::vector<ScorerPtr> sub_scorers;
for (const auto& sub_weight : _sub_weights) {
sub_scorers.emplace_back(sub_weight->scorer(reader));
}
return sub_scorers;
}

OperatorType _type;
std::vector<WeightPtr> _sub_weights;
ScoreCombinerPtrT _score_combiner;
};

} // namespace doris::segment_v2::inverted_index::query_v2
Loading