Skip to content

Commit b1e24fd

Browse files
authored
Merge pull request #33854 from vespa-engine/arnej/simple-filter-with-streaming
implement (simple) group filter also in streaming mode
2 parents 467e4fd + 8f8dfc8 commit b1e24fd

5 files changed

Lines changed: 33 additions & 22 deletions

File tree

searchlib/src/vespa/searchlib/aggregation/modifiers.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace search::aggregation {
1616
bool
1717
AttributeNodeReplacer::check(const vespalib::Identifiable &obj) const
1818
{
19-
return obj.getClass().inherits(GroupingLevel::classId) || obj.getClass().inherits(AggregationResult::classId) || obj.getClass().inherits(MultiArgFunctionNode::classId);
19+
return obj.getClass().inherits(ExpressionTree::classId) || obj.getClass().inherits(AggregationResult::classId) || obj.getClass().inherits(MultiArgFunctionNode::classId);
2020
}
2121

2222
void
@@ -35,10 +35,9 @@ AttributeNodeReplacer::replaceRecurse(ExpressionNode * exp, std::function<void(E
3535
void
3636
AttributeNodeReplacer::execute(vespalib::Identifiable &obj)
3737
{
38-
if (obj.getClass().inherits(GroupingLevel::classId)) {
39-
auto & g(static_cast<GroupingLevel &>(obj));
40-
replaceRecurse(g.getExpression().getRoot(), [&g](ExpressionNodeUP replacement) { g.setExpression(std::move(replacement)); });
41-
g.groupPrototype().select(*this, *this);
38+
if (obj.getClass().inherits(ExpressionTree::classId)) {
39+
auto & g(static_cast<ExpressionTree &>(obj));
40+
replaceRecurse(g.getRoot(), [&g](ExpressionNodeUP replacement) noexcept { g.changeRoot(std::move(replacement)); });
4241
} else if(obj.getClass().inherits(AggregationResult::classId)) {
4342
auto & a(static_cast<AggregationResult &>(obj));
4443
replaceRecurse(a.getExpression(), [&a](ExpressionNodeUP replacement) { a.setExpression(std::move(replacement)); });

searchlib/src/vespa/searchlib/expression/expressiontree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ExpressionTree : public ExpressionNode
6363
bool execute(const document::Document & doc, HitRank rank) const;
6464
const ExpressionNode * getRoot() const { return _root.get(); }
6565
ExpressionNode * getRoot() { return _root.get(); }
66+
void changeRoot(ExpressionNode::UP root) { _root = std::move(root); }
6667
const ResultNode * getResult() const override { return _root->getResult(); }
6768
friend vespalib::Serializer & operator << (vespalib::Serializer & os, const ExpressionTree & et);
6869
friend vespalib::Deserializer & operator >> (vespalib::Deserializer & is, ExpressionTree & et);

searchlib/src/vespa/searchlib/expression/filter_predicate_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class FilterPredicateNode : public vespalib::Identifiable
1515
virtual FilterPredicateNode * clone() const = 0;
1616
//virtual bool valid() const = 0;
1717
virtual bool allow(DocId docId, HitRank rank) = 0;
18-
bool allow(const document::Document &, HitRank) { return true; }
18+
virtual bool allow(const document::Document &, HitRank) = 0;
1919
};
2020

2121
class TruePredicateNode : public FilterPredicateNode {
@@ -24,6 +24,7 @@ class TruePredicateNode : public FilterPredicateNode {
2424
TruePredicateNode * clone() const override { return new TruePredicateNode(); }
2525
//bool valid() const override { return true; }
2626
bool allow(DocId, HitRank) override { return true; }
27+
bool allow(const document::Document &, HitRank) override { return true; }
2728
static TruePredicateNode instance;
2829
};
2930

searchlib/src/vespa/searchlib/expression/regex_predicate_node.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,34 @@ void RegexPredicateNode::RE::compile() {
1515
regex = Regex::from_pattern(pattern, Regex::Options::None);
1616
}
1717

18+
bool RegexPredicateNode::check(const ResultNode* result) const {
19+
if (result->inherits(ResultNodeVector::classId)) {
20+
const auto * rv = static_cast<const ResultNodeVector *>(result);
21+
for (size_t i = 0; i < rv->size(); i++) {
22+
HoldString tmp(*rv, i);
23+
if (_re.regex.full_match(tmp)) return true;
24+
}
25+
return false;
26+
} else {
27+
HoldString tmp(*result);
28+
return _re.regex.full_match(tmp);
29+
}
30+
}
31+
32+
bool RegexPredicateNode::allow(const document::Document & doc, HitRank rank) {
33+
if (_argument.getRoot()) {
34+
_argument.execute(doc, rank);
35+
return check(_argument.getResult());
36+
}
37+
return false;
38+
}
39+
1840
bool RegexPredicateNode::allow(DocId docId, HitRank rank) {
19-
bool isMatch = false;
2041
if (_argument.getRoot()) {
2142
_argument.execute(docId, rank);
22-
const ResultNode* result = _argument.getResult();
23-
if (result->inherits(ResultNodeVector::classId)) {
24-
const auto * rv = static_cast<const ResultNodeVector *>(result);
25-
for (size_t i = 0; i < rv->size(); i++) {
26-
HoldString tmp(*rv, i);
27-
isMatch = _re.regex.full_match(tmp);
28-
if (isMatch) break;
29-
}
30-
} else {
31-
HoldString tmp(*result);
32-
isMatch = _re.regex.full_match(tmp);
33-
}
34-
43+
return check(_argument.getResult());
3544
}
36-
return isMatch;
45+
return false;
3746
}
3847

3948
RegexPredicateNode::RegexPredicateNode() noexcept : _re(), _argument() {}

searchlib/src/vespa/searchlib/expression/regex_predicate_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class RegexPredicateNode : public FilterPredicateNode {
2727
RE _re;
2828
ExpressionTree _argument;
2929

30+
bool check(const ResultNode* result) const;
3031
public:
3132
RegexPredicateNode() noexcept;
3233
~RegexPredicateNode();
@@ -38,7 +39,7 @@ class RegexPredicateNode : public FilterPredicateNode {
3839
DECLARE_IDENTIFIABLE_NS2(search, expression, RegexPredicateNode);
3940
DECLARE_NBO_SERIALIZE;
4041
bool allow(DocId docId, HitRank rank) override;
41-
// bool allow(const document::Document &, HitRank) { return true; }
42+
bool allow(const document::Document &, HitRank) override;
4243
void visitMembers(vespalib::ObjectVisitor& visitor) const override;
4344
void selectMembers(const vespalib::ObjectPredicate& predicate,
4445
vespalib::ObjectOperation& operation) override;

0 commit comments

Comments
 (0)