summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2024-02-06 14:38:33 +0100
committerTor Egge <Tor.Egge@online.no>2024-02-06 14:38:33 +0100
commit624bb3303a021ab3f3065c8d2be3d399054a82cf (patch)
tree90ee218ab735fa38ac1a5cc6c9bbe8afef0d68bb /searchlib
parent9ae25d8c35f7a15fdb8f45eee4ca34afe8cd483a (diff)
Handle search::streaming::PhraseQueryNode as a leaf in the query tree.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/query/streaming/phrase_query_node_test.cpp13
-rw-r--r--searchlib/src/tests/query/streaming_query_test.cpp24
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.cpp34
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.h5
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/query.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/query.h5
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynode.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynode.h4
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.h4
10 files changed, 20 insertions, 107 deletions
diff --git a/searchlib/src/tests/query/streaming/phrase_query_node_test.cpp b/searchlib/src/tests/query/streaming/phrase_query_node_test.cpp
index 2459fe2f01c..a6b3a1ffe05 100644
--- a/searchlib/src/tests/query/streaming/phrase_query_node_test.cpp
+++ b/searchlib/src/tests/query/streaming/phrase_query_node_test.cpp
@@ -34,11 +34,9 @@ TEST(PhraseQueryNodeTest, test_phrase_evaluate)
vespalib::string stackDump = StackDumpCreator::create(*node);
QueryNodeResultFactory empty;
Query q(empty, stackDump);
- QueryNodeRefList phrases;
- q.getPhrases(phrases);
- QueryTermList terms;
- q.getLeaves(terms);
- for (QueryTerm * qt : terms) {
+ auto& p = dynamic_cast<PhraseQueryNode&>(q.getRoot());
+ auto& terms = p.get_terms();
+ for (auto& qt : terms) {
qt->resizeFieldId(1);
}
@@ -69,8 +67,7 @@ TEST(PhraseQueryNodeTest, test_phrase_evaluate)
terms[1]->add(5, 0, 1, 1);
terms[2]->add(5, 0, 1, 0);
HitList hits;
- auto * p = static_cast<PhraseQueryNode *>(phrases[0]);
- p->evaluateHits(hits);
+ p.evaluateHits(hits);
ASSERT_EQ(3u, hits.size());
EXPECT_EQ(0u, hits[0].field_id());
EXPECT_EQ(0u, hits[0].element_id());
@@ -81,7 +78,7 @@ TEST(PhraseQueryNodeTest, test_phrase_evaluate)
EXPECT_EQ(3u, hits[2].field_id());
EXPECT_EQ(0u, hits[2].element_id());
EXPECT_EQ(0u, hits[2].position());
- EXPECT_TRUE(p->evaluate());
+ EXPECT_TRUE(p.evaluate());
}
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/searchlib/src/tests/query/streaming_query_test.cpp b/searchlib/src/tests/query/streaming_query_test.cpp
index cf72b71d6ad..19a2a0876c6 100644
--- a/searchlib/src/tests/query/streaming_query_test.cpp
+++ b/searchlib/src/tests/query/streaming_query_test.cpp
@@ -404,26 +404,20 @@ TEST(StreamingQueryTest, test_get_query_parts)
QueryNodeResultFactory empty;
Query q(empty, stackDump);
QueryTermList terms;
- QueryNodeRefList phrases;
q.getLeaves(terms);
- q.getPhrases(phrases);
- ASSERT_TRUE(terms.size() == 7);
- ASSERT_TRUE(phrases.size() == 2);
- {
- QueryTermList pts;
- phrases[0]->getLeaves(pts);
+ ASSERT_TRUE(terms.size() == 4);
+ PhraseQueryNode* null = nullptr;
+ EXPECT_EQ(null, dynamic_cast<PhraseQueryNode*>(terms[0]));
+ EXPECT_NE(null, dynamic_cast<PhraseQueryNode*>(terms[1]));
+ EXPECT_EQ(null, dynamic_cast<PhraseQueryNode*>(terms[2]));
+ EXPECT_NE(null, dynamic_cast<PhraseQueryNode*>(terms[3]));
+ {
+ auto& pts = dynamic_cast<PhraseQueryNode&>(*terms[1]).get_terms();
ASSERT_TRUE(pts.size() == 3);
- for (size_t i = 0; i < 3; ++i) {
- EXPECT_EQ(pts[i], terms[i + 1]);
- }
}
{
- QueryTermList pts;
- phrases[1]->getLeaves(pts);
+ auto& pts = dynamic_cast<PhraseQueryNode&>(*terms[3]).get_terms();
ASSERT_TRUE(pts.size() == 2);
- for (size_t i = 0; i < 2; ++i) {
- EXPECT_EQ(pts[i], terms[i + 5]);
- }
}
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.cpp b/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.cpp
index 95781b58019..9cd8d41d33d 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.cpp
@@ -20,46 +20,12 @@ PhraseQueryNode::evaluate() const
return ! evaluateHits(hl).empty();
}
-void
-PhraseQueryNode::getPhrases(QueryNodeRefList & tl)
-{
- tl.push_back(this);
-}
-
-void
-PhraseQueryNode::getPhrases(ConstQueryNodeRefList & tl) const
-{
- tl.push_back(this);
-}
-
-void
-PhraseQueryNode::getLeaves(QueryTermList & tl)
-{
- for (const auto& node : get_terms()) {
- node->getLeaves(tl);
- }
-}
-
-void
-PhraseQueryNode::getLeaves(ConstQueryTermList & tl) const
-{
- for (const auto& node : get_terms()) {
- node->getLeaves(tl);
- }
-}
-
size_t
PhraseQueryNode::width() const
{
return get_terms().size();
}
-MultiTerm*
-PhraseQueryNode::as_multi_term() noexcept
-{
- return nullptr;
-}
-
const HitList &
PhraseQueryNode::evaluateHits(HitList & hl) const
{
diff --git a/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.h b/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.h
index 763cb1d6b8f..0d443ac4527 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/phrase_query_node.h
@@ -17,13 +17,8 @@ public:
~PhraseQueryNode() override;
bool evaluate() const override;
const HitList & evaluateHits(HitList & hl) const override;
- void getPhrases(QueryNodeRefList & tl) override;
- void getPhrases(ConstQueryNodeRefList & tl) const override;
void unpack_match_data(uint32_t docid, const fef::ITermData& td, fef::MatchData& match_data) override;
- void getLeaves(QueryTermList & tl) override;
- void getLeaves(ConstQueryTermList & tl) const override;
size_t width() const override;
- MultiTerm* as_multi_term() noexcept override;
};
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/query.cpp b/searchlib/src/vespa/searchlib/query/streaming/query.cpp
index f1b3a804c50..77424fb2d62 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/query.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/query.cpp
@@ -63,22 +63,6 @@ QueryConnector::getLeaves(ConstQueryTermList & tl) const
}
}
-void
-QueryConnector::getPhrases(QueryNodeRefList & tl)
-{
- for (const auto & node : _children) {
- node->getPhrases(tl);
- }
-}
-
-void
-QueryConnector::getPhrases(ConstQueryNodeRefList & tl) const
-{
- for (const auto & node : _children) {
- node->getPhrases(tl);
- }
-}
-
size_t
QueryConnector::depth() const
{
@@ -218,20 +202,6 @@ Query::getLeaves(ConstQueryTermList & tl) const {
}
void
-Query::getPhrases(QueryNodeRefList & tl) {
- if (valid()) {
- _root->getPhrases(tl);
- }
-}
-
-void
-Query::getPhrases(ConstQueryNodeRefList & tl) const {
- if (valid()) {
- _root->getPhrases(tl);
- }
-}
-
-void
Query::reset() {
if (valid()) {
_root->reset();
diff --git a/searchlib/src/vespa/searchlib/query/streaming/query.h b/searchlib/src/vespa/searchlib/query/streaming/query.h
index 5296d3a4f69..e91a2f91dc5 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/query.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/query.h
@@ -19,8 +19,6 @@ public:
void reset() override;
void getLeaves(QueryTermList & tl) override;
void getLeaves(ConstQueryTermList & tl) const override;
- void getPhrases(QueryNodeRefList & tl) override;
- void getPhrases(ConstQueryNodeRefList & tl) const override;
size_t depth() const override;
size_t width() const override;
virtual void visitMembers(vespalib::ObjectVisitor &visitor) const;
@@ -139,9 +137,6 @@ public:
/// Will get all leafnodes.
void getLeaves(QueryTermList & tl);
void getLeaves(ConstQueryTermList & tl) const;
- /// Gives you all phrases of this tree.
- void getPhrases(QueryNodeRefList & tl);
- void getPhrases(ConstQueryNodeRefList & tl) const;
bool evaluate() const;
size_t depth() const;
size_t width() const;
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
index a0abdcd28fb..44df253a2fd 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
@@ -265,6 +265,8 @@ QueryNode::build_phrase_term(const QueryNodeResultFactory& factory, SimpleQueryS
{
auto phrase = std::make_unique<PhraseQueryNode>(factory.create(), queryRep.getIndexName(), queryRep.getArity());
auto arity = queryRep.getArity();
+ phrase->setWeight(queryRep.GetWeight());
+ phrase->setUniqueId(queryRep.getUniqueId());
for (size_t i = 0; i < arity; ++i) {
queryRep.next();
auto qn = Build(phrase.get(), factory, queryRep, false);
@@ -274,6 +276,10 @@ QueryNode::build_phrase_term(const QueryNodeResultFactory& factory, SimpleQueryS
std::unique_ptr<QueryTerm> qt(qtp);
phrase->add_term(std::move(qt));
}
+ if (!phrase->get_terms().empty()) {
+ auto& first = *phrase->get_terms().front();
+ phrase->setIndex(first.getIndex());
+ }
return phrase;
}
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynode.h b/searchlib/src/vespa/searchlib/query/streaming/querynode.h
index 01974c70843..4c7d9e88930 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynode.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynode.h
@@ -50,10 +50,6 @@ class QueryNode
virtual void getLeaves(QueryTermList & tl) = 0;
/// Gives you all leafs of this tree. Indicating that they are all const.
virtual void getLeaves(ConstQueryTermList & tl) const = 0;
- /// Gives you all phrases of this tree.
- virtual void getPhrases(QueryNodeRefList & tl) = 0;
- /// Gives you all phrases of this tree. Indicating that they are all const.
- virtual void getPhrases(ConstQueryNodeRefList & tl) const = 0;
virtual void setIndex(const vespalib::string & index) = 0;
virtual const vespalib::string & getIndex() const = 0;
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
index dbaeaa5d895..f01f815e673 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
@@ -86,8 +86,6 @@ QueryTerm::QueryTerm(std::unique_ptr<QueryNodeResultBase> org, stringref termS,
}
}
-void QueryTerm::getPhrases(QueryNodeRefList & tl) { (void) tl; }
-void QueryTerm::getPhrases(ConstQueryNodeRefList & tl) const { (void) tl; }
void QueryTerm::getLeaves(QueryTermList & tl) { tl.push_back(this); }
void QueryTerm::getLeaves(ConstQueryTermList & tl) const { tl.push_back(this); }
bool QueryTerm::evaluate() const { return !_hitList.empty(); }
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
index de043237cff..2eaecb86854 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
@@ -75,10 +75,6 @@ public:
void reset() override;
void getLeaves(QueryTermList & tl) override;
void getLeaves(ConstQueryTermList & tl) const override;
- /// Gives you all phrases of this tree.
- void getPhrases(QueryNodeRefList & tl) override;
- /// Gives you all phrases of this tree. Indicating that they are all const.
- void getPhrases(ConstQueryNodeRefList & tl) const override;
uint32_t add(uint32_t field_id, uint32_t element_id, int32_t element_weight, uint32_t position);
void set_element_length(uint32_t hitlist_idx, uint32_t element_length);