summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2021-10-19 11:08:39 +0000
committerArne H Juul <arnej@yahooinc.com>2021-10-19 11:08:39 +0000
commita7f289541ff64edfeea11d4db4310c5245f1f823 (patch)
tree29c2e575f3f62633e1bdf5ad93290c29211583a0
parent4a93eeb139aeb500057c9527f19b0c47db2f1a5c (diff)
use custom types for true/false (NodeTypes::True, ProtonTrue, etc)
-rw-r--r--searchcore/src/tests/proton/matching/unpacking_iterators_optimizer/unpacking_iterators_optimizer_test.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp5
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/querynodes.h5
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/termdatafromnode.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/unpacking_iterators_optimizer.cpp4
-rw-r--r--searchcorespi/src/vespa/searchcorespi/index/indexcollection.cpp2
-rw-r--r--searchlib/src/tests/query/customtypevisitor_test.cpp16
-rw-r--r--searchlib/src/tests/query/querybuilder_test.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/const_bool_nodes.h2
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/customtypetermvisitor.h4
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/customtypevisitor.h6
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/querybuilder.h14
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/simplequery.h5
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/fake_searchable.cpp2
15 files changed, 59 insertions, 22 deletions
diff --git a/searchcore/src/tests/proton/matching/unpacking_iterators_optimizer/unpacking_iterators_optimizer_test.cpp b/searchcore/src/tests/proton/matching/unpacking_iterators_optimizer/unpacking_iterators_optimizer_test.cpp
index 68960e0f919..ffd08b3bbef 100644
--- a/searchcore/src/tests/proton/matching/unpacking_iterators_optimizer/unpacking_iterators_optimizer_test.cpp
+++ b/searchcore/src/tests/proton/matching/unpacking_iterators_optimizer/unpacking_iterators_optimizer_test.cpp
@@ -67,8 +67,8 @@ struct DumpQuery : QueryVisitor {
void visit(PredicateQuery &) override {}
void visit(RegExpTerm &) override {}
void visit(NearestNeighborTerm &) override {}
- void visit(search::query::TrueQueryNode &) override {}
- void visit(search::query::FalseQueryNode &) override {}
+ void visit(TrueQueryNode &) override {}
+ void visit(FalseQueryNode &) override {}
};
std::string dump_query(Node &root) {
diff --git a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
index a12d556ff5f..9be5920c0ed 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
@@ -159,11 +159,10 @@ protected:
void visit(ProtonPredicateQuery &n) override { buildTerm(n); }
void visit(ProtonRegExpTerm &n) override { buildTerm(n); }
void visit(ProtonNearestNeighborTerm &n) override { buildTerm(n); }
-
- void visit(search::query::TrueQueryNode &) override {
+ void visit(ProtonTrue &) override {
_result = std::make_unique<AlwaysTrueBlueprint>();
}
- void visit(search::query::FalseQueryNode &) override {
+ void visit(ProtonFalse &) override {
_result = std::make_unique<EmptyBlueprint>();
}
diff --git a/searchcore/src/vespa/searchcore/proton/matching/querynodes.h b/searchcore/src/vespa/searchcore/proton/matching/querynodes.h
index 2ebd52d7fa7..084c533fa55 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/querynodes.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/querynodes.h
@@ -114,7 +114,8 @@ typedef search::query::SimpleOr ProtonOr;
typedef search::query::SimpleRank ProtonRank;
typedef search::query::SimpleWeakAnd ProtonWeakAnd;
typedef search::query::SimpleSameElement ProtonSameElement;
-
+typedef search::query::SimpleTrue ProtonTrue;
+typedef search::query::SimpleFalse ProtonFalse;
struct ProtonEquiv final : public ProtonTermBase<search::query::Equiv> {
search::fef::MatchDataLayout children_mdl;
@@ -161,6 +162,8 @@ struct ProtonNodeTypes {
typedef ProtonPredicateQuery PredicateQuery;
typedef ProtonRegExpTerm RegExpTerm;
typedef ProtonNearestNeighborTerm NearestNeighborTerm;
+ typedef ProtonTrue True;
+ typedef ProtonFalse False;
};
}
diff --git a/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp b/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp
index 9e415ed699f..34cb5369c1e 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp
@@ -67,8 +67,8 @@ public:
void visit(ProtonPredicateQuery &) override {}
void visit(ProtonRegExpTerm &n) override { visitTerm(n); }
void visit(ProtonNearestNeighborTerm &) override {}
- void visit(search::query::TrueQueryNode &) override {}
- void visit(search::query::FalseQueryNode &) override {}
+ void visit(ProtonTrue &) override {}
+ void visit(ProtonFalse &) override {}
};
} // namespace proton::matching::<unnamed>
diff --git a/searchcore/src/vespa/searchcore/proton/matching/termdatafromnode.cpp b/searchcore/src/vespa/searchcore/proton/matching/termdatafromnode.cpp
index c752ed76909..c2abeaa36ee 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/termdatafromnode.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/termdatafromnode.cpp
@@ -26,8 +26,8 @@ struct TermDataFromTermVisitor
void visit(ProtonRank &) override {}
void visit(ProtonWeakAnd &) override {}
void visit(ProtonSameElement &) override { }
- void visit(search::query::TrueQueryNode &) override {}
- void visit(search::query::FalseQueryNode &) override {}
+ void visit(ProtonTrue &) override {}
+ void visit(ProtonFalse &) override {}
void visit(ProtonWeightedSetTerm &n) override { visitTerm(n); }
void visit(ProtonDotProduct &n) override { visitTerm(n); }
diff --git a/searchcore/src/vespa/searchcore/proton/matching/unpacking_iterators_optimizer.cpp b/searchcore/src/vespa/searchcore/proton/matching/unpacking_iterators_optimizer.cpp
index bcb482a58ab..d60bc53aa57 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/unpacking_iterators_optimizer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/unpacking_iterators_optimizer.cpp
@@ -57,8 +57,8 @@ struct TermExpander : QueryVisitor {
void visit(PredicateQuery &) override {}
void visit(RegExpTerm &) override {}
void visit(NearestNeighborTerm &) override {}
- void visit(search::query::TrueQueryNode &) override {}
- void visit(search::query::FalseQueryNode &) override {}
+ void visit(TrueQueryNode &) override {}
+ void visit(FalseQueryNode &) override {}
void flush(Intermediate &parent) {
for (Node::UP &term: terms) {
diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexcollection.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexcollection.cpp
index 9cad48a8058..49348d77c08 100644
--- a/searchcorespi/src/vespa/searchcorespi/index/indexcollection.cpp
+++ b/searchcorespi/src/vespa/searchcorespi/index/indexcollection.cpp
@@ -204,7 +204,7 @@ private:
void visit(RegExpTerm &n) override { visitTerm(n); }
void visit(NearestNeighborTerm &n) override { visitTerm(n); }
void visit(TrueQueryNode &) override {}
- void visit(FalseQueryNode &) override {}
+ void visit(FalseQueryNode &) override {}
public:
CreateBlueprintVisitor(const IIndexCollection &indexes,
diff --git a/searchlib/src/tests/query/customtypevisitor_test.cpp b/searchlib/src/tests/query/customtypevisitor_test.cpp
index 112e49cd1c1..da3d8ffa115 100644
--- a/searchlib/src/tests/query/customtypevisitor_test.cpp
+++ b/searchlib/src/tests/query/customtypevisitor_test.cpp
@@ -42,7 +42,11 @@ struct MyDotProduct : DotProduct { MyDotProduct() : DotProduct(0, "view", 0, Wei
struct MyWandTerm : WandTerm { MyWandTerm() : WandTerm(0, "view", 0, Weight(42), 57, 67, 77.7) {} };
struct MyPredicateQuery : InitTerm<PredicateQuery> {};
struct MyRegExpTerm : InitTerm<RegExpTerm> {};
-struct MyNearestNeighborTerm : NearestNeighborTerm {};
+struct MyNearestNeighborTerm : NearestNeighborTerm {
+ MyNearestNeighborTerm() : NearestNeighborTerm("qt", "fn", 0, Weight(42), 10, true, 666, 1234.5) {}
+};
+struct MyTrue : TrueQueryNode {};
+struct MyFalse : FalseQueryNode {};
struct MyQueryNodeTypes {
typedef MyAnd And;
@@ -68,6 +72,8 @@ struct MyQueryNodeTypes {
typedef MyPredicateQuery PredicateQuery;
typedef MyRegExpTerm RegExpTerm;
typedef MyNearestNeighborTerm NearestNeighborTerm;
+ typedef MyFalse False;
+ typedef MyTrue True;
};
class MyCustomVisitor : public CustomTypeVisitor<MyQueryNodeTypes>
@@ -104,8 +110,8 @@ public:
void visit(MyPredicateQuery &) override { setVisited<MyPredicateQuery>(); }
void visit(MyRegExpTerm &) override { setVisited<MyRegExpTerm>(); }
void visit(MyNearestNeighborTerm &) override { setVisited<MyNearestNeighborTerm>(); }
- void visit(TrueQueryNode &) override {}
- void visit(FalseQueryNode &) override {}
+ void visit(MyTrue &) override { setVisited<MyTrue>(); }
+ void visit(MyFalse &) override { setVisited<MyFalse>(); }
};
template <class T>
@@ -138,6 +144,10 @@ TEST("customtypevisitor_test") {
requireThatNodeIsVisited<MyWandTerm>();
requireThatNodeIsVisited<MyPredicateQuery>();
requireThatNodeIsVisited<MyRegExpTerm>();
+ requireThatNodeIsVisited<MyLocationTerm>();
+ requireThatNodeIsVisited<MyNearestNeighborTerm>();
+ requireThatNodeIsVisited<MyTrue>();
+ requireThatNodeIsVisited<MyFalse>();
}
} // namespace
diff --git a/searchlib/src/tests/query/querybuilder_test.cpp b/searchlib/src/tests/query/querybuilder_test.cpp
index 0c784287e5c..b421084bbef 100644
--- a/searchlib/src/tests/query/querybuilder_test.cpp
+++ b/searchlib/src/tests/query/querybuilder_test.cpp
@@ -409,6 +409,8 @@ struct MyNearestNeighborTerm : NearestNeighborTerm {
: NearestNeighborTerm(query_tensor_name, field_name, i, w, target_num_hits, allow_approximate, explore_additional_hits, distance_threshold)
{}
};
+struct MyTrue : TrueQueryNode {};
+struct MyFalse : FalseQueryNode {};
struct MyQueryNodeTypes {
typedef MyAnd And;
@@ -434,6 +436,8 @@ struct MyQueryNodeTypes {
typedef MyPredicateQuery PredicateQuery;
typedef MyRegExpTerm RegExpTerm;
typedef MyNearestNeighborTerm NearestNeighborTerm;
+ typedef MyTrue True;
+ typedef MyFalse False;
};
TEST("require that Custom Query Trees Can Be Built") {
diff --git a/searchlib/src/vespa/searchlib/query/tree/const_bool_nodes.h b/searchlib/src/vespa/searchlib/query/tree/const_bool_nodes.h
index fae7c943319..fd31f3bf8f2 100644
--- a/searchlib/src/vespa/searchlib/query/tree/const_bool_nodes.h
+++ b/searchlib/src/vespa/searchlib/query/tree/const_bool_nodes.h
@@ -7,11 +7,13 @@
namespace search::query {
class TrueQueryNode : public Node {
+public:
~TrueQueryNode();
void accept(QueryVisitor &visitor) override { visitor.visit(*this); }
};
class FalseQueryNode : public Node {
+public:
~FalseQueryNode();
void accept(QueryVisitor &visitor) override { visitor.visit(*this); }
};
diff --git a/searchlib/src/vespa/searchlib/query/tree/customtypetermvisitor.h b/searchlib/src/vespa/searchlib/query/tree/customtypetermvisitor.h
index cc593840d87..80b854acaf9 100644
--- a/searchlib/src/vespa/searchlib/query/tree/customtypetermvisitor.h
+++ b/searchlib/src/vespa/searchlib/query/tree/customtypetermvisitor.h
@@ -29,8 +29,8 @@ private:
void visit(typename NodeTypes::SameElement &n) override { visitChildren(n); }
// leaf nodes without terms:
- void visit(TrueQueryNode &) override {}
- void visit(FalseQueryNode &) override {}
+ void visit(typename NodeTypes::True &) override {}
+ void visit(typename NodeTypes::False &) override {}
// phrases and weighted set terms are conceptual leaf nodes and
// should be handled that way.
diff --git a/searchlib/src/vespa/searchlib/query/tree/customtypevisitor.h b/searchlib/src/vespa/searchlib/query/tree/customtypevisitor.h
index aa4408d0dbe..0e1f590c348 100644
--- a/searchlib/src/vespa/searchlib/query/tree/customtypevisitor.h
+++ b/searchlib/src/vespa/searchlib/query/tree/customtypevisitor.h
@@ -50,6 +50,8 @@ public:
virtual void visit(typename NodeTypes::PredicateQuery &) = 0;
virtual void visit(typename NodeTypes::RegExpTerm &) = 0;
virtual void visit(typename NodeTypes::NearestNeighborTerm &) = 0;
+ virtual void visit(typename NodeTypes::True &) = 0;
+ virtual void visit(typename NodeTypes::False &) = 0;
private:
// Route QueryVisit requests to the correct custom type.
@@ -77,6 +79,8 @@ private:
typedef typename NodeTypes::PredicateQuery TPredicateQuery;
typedef typename NodeTypes::RegExpTerm TRegExpTerm;
typedef typename NodeTypes::NearestNeighborTerm TNearestNeighborTerm;
+ typedef typename NodeTypes::True TTrue;
+ typedef typename NodeTypes::False TFalse;
void visit(And &n) override { visit(static_cast<TAnd&>(n)); }
void visit(AndNot &n) override { visit(static_cast<TAndNot&>(n)); }
@@ -101,6 +105,8 @@ private:
void visit(PredicateQuery &n) override { visit(static_cast<TPredicateQuery&>(n)); }
void visit(RegExpTerm &n) override { visit(static_cast<TRegExpTerm&>(n)); }
void visit(NearestNeighborTerm &n) override { visit(static_cast<TNearestNeighborTerm&>(n)); }
+ void visit(TrueQueryNode &n) override { visit(static_cast<TTrue&>(n)); }
+ void visit(FalseQueryNode &n) override { visit(static_cast<TFalse&>(n)); }
};
}
diff --git a/searchlib/src/vespa/searchlib/query/tree/querybuilder.h b/searchlib/src/vespa/searchlib/query/tree/querybuilder.h
index 3da8b32b9ee..1df73ededac 100644
--- a/searchlib/src/vespa/searchlib/query/tree/querybuilder.h
+++ b/searchlib/src/vespa/searchlib/query/tree/querybuilder.h
@@ -99,6 +99,12 @@ public:
// You may specialize these functions for your own traits class to have full
// control of the query node instantiation.
+template <class NodeTypes>
+typename NodeTypes::True *create_true() { return new typename NodeTypes::True; }
+
+template <class NodeTypes>
+typename NodeTypes::False *create_false() { return new typename NodeTypes::False; }
+
// Intermediate nodes
template <class NodeTypes>
typename NodeTypes::And *createAnd() { return new typename NodeTypes::And; }
@@ -329,8 +335,12 @@ public:
adjustWeight(weight);
return addTerm(create_nearest_neighbor_term<NodeTypes>(query_tensor_name, field_name, id, weight, target_num_hits, allow_approximate, explore_additional_hits, distance_threshold));
}
- void add_true_node() { addTerm(new TrueQueryNode()); }
- void add_false_node() { addTerm(new TrueQueryNode()); }
+ typename NodeTypes::True &add_true_node() {
+ return addTerm(create_true<NodeTypes>());
+ }
+ typename NodeTypes::False &add_false_node() {
+ return addTerm(create_false<NodeTypes>());
+ }
};
}
diff --git a/searchlib/src/vespa/searchlib/query/tree/simplequery.h b/searchlib/src/vespa/searchlib/query/tree/simplequery.h
index 44d869bc8bf..4829a569921 100644
--- a/searchlib/src/vespa/searchlib/query/tree/simplequery.h
+++ b/searchlib/src/vespa/searchlib/query/tree/simplequery.h
@@ -7,11 +7,14 @@
#pragma once
+#include "const_bool_nodes.h"
#include "intermediatenodes.h"
#include "termnodes.h"
namespace search::query {
+struct SimpleTrue : TrueQueryNode {};
+struct SimpleFalse : FalseQueryNode {};
struct SimpleAnd : And {};
struct SimpleAndNot : AndNot {};
struct SimpleNear : Near { SimpleNear(size_t dist) : Near(dist) {} };
@@ -119,6 +122,8 @@ struct SimpleQueryNodeTypes {
using And = SimpleAnd;
using AndNot = SimpleAndNot;
using Equiv = SimpleEquiv;
+ using False = SimpleFalse;
+ using True = SimpleTrue;
using NumberTerm = SimpleNumberTerm;
using LocationTerm = SimpleLocationTerm;
using Near = SimpleNear;
diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_searchable.cpp b/searchlib/src/vespa/searchlib/queryeval/fake_searchable.cpp
index 838a95d483a..519f6e81774 100644
--- a/searchlib/src/vespa/searchlib/queryeval/fake_searchable.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/fake_searchable.cpp
@@ -6,7 +6,6 @@
#include "create_blueprint_visitor_helper.h"
#include <vespa/vespalib/objects/visit.h>
-using search::query::FalseQueryNode;
using search::query::LocationTerm;
using search::query::NearestNeighborTerm;
using search::query::Node;
@@ -18,7 +17,6 @@ using search::query::RegExpTerm;
using search::query::StringTerm;
using search::query::SubstringTerm;
using search::query::SuffixTerm;
-using search::query::TrueQueryNode;
namespace search::queryeval {