diff options
author | Henning Baldersheim <balder@oath.com> | 2018-06-05 15:45:28 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-06-05 15:46:55 +0200 |
commit | d8a156e1d0aeac5c2d674b3b7b479d43d77ab22a (patch) | |
tree | 78a868ef36b83506ebfb98a9d2bc9fd1b5c1bccc /searchlib | |
parent | a010d42a3d2397a744362a22e673c63fd49e0ae3 (diff) |
Add testing of SameElementQueryNode
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/query/query-old.cpp | 76 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/query/query.cpp | 26 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/query/query.h | 1 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/query/querynode.cpp | 5 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/query/queryterm.cpp | 6 |
5 files changed, 95 insertions, 19 deletions
diff --git a/searchlib/src/tests/query/query-old.cpp b/searchlib/src/tests/query/query-old.cpp index 837f0060bf3..b475540bfc3 100644 --- a/searchlib/src/tests/query/query-old.cpp +++ b/searchlib/src/tests/query/query-old.cpp @@ -651,4 +651,80 @@ TEST("require that we do not break the stack on bad query") { EXPECT_FALSE(term.isValid()); } +TEST("testPhraseEvaluate") { + QueryBuilder<SimpleQueryNodeTypes> builder; + builder.addSameElement(3, "field"); + { + builder.addStringTerm("a", "f1", 0, Weight(0)); + builder.addStringTerm("b", "f2", 1, Weight(0)); + builder.addStringTerm("c", "f3", 2, Weight(0)); + } + Node::UP node = builder.build(); + vespalib::string stackDump = StackDumpCreator::create(*node); + QueryNodeResultFactory empty; + Query q(empty, stackDump); + SameElementQueryNode * p = dynamic_cast<SameElementQueryNode *>(&q.getRoot()); + EXPECT_TRUE(p != nullptr); + EXPECT_EQUAL("field", p->getIndex()); + EXPECT_EQUAL(3u, p->size()); + EXPECT_TRUE(dynamic_cast<const QueryTerm *>((*p)[0].get()) != nullptr); + EXPECT_EQUAL("field.f1", (*p)[0]->getIndex()); + EXPECT_TRUE(dynamic_cast<const QueryTerm *>((*p)[1].get()) != nullptr); + EXPECT_EQUAL("field.f2", (*p)[1]->getIndex()); + EXPECT_TRUE(dynamic_cast<const QueryTerm *>((*p)[2].get()) != nullptr); + EXPECT_EQUAL("field.f3", (*p)[2]->getIndex()); + QueryTermList terms; + q.getLeafs(terms); + EXPECT_EQUAL(3u, terms.size()); + for (QueryTerm * qt : terms) { + qt->resizeFieldId(3); + } + + // field 0 + terms[0]->add(0, 0, 0, 1); + terms[0]->add(0, 0, 1, 1); + terms[0]->add(0, 0, 2, 1); + terms[0]->add(0, 0, 3, 1); + terms[0]->add(0, 0, 4, 1); + terms[0]->add(0, 0, 5, 1); + + terms[1]->add(0, 1, 0, 1); + terms[1]->add(0, 1, 1, 1); + terms[1]->add(0, 1, 2, 1); + terms[1]->add(0, 1, 4, 1); + terms[1]->add(0, 1, 5, 1); + terms[1]->add(0, 1, 6, 1); + + terms[2]->add(0, 2, 0, 1); + terms[2]->add(0, 2, 2, 1); + terms[2]->add(0, 2, 4, 1); + terms[2]->add(0, 2, 5, 1); + terms[2]->add(0, 2, 6, 1); + HitList hits; + + p->evaluateHits(hits); + EXPECT_EQUAL(4u, hits.size()); + EXPECT_EQUAL(0u, hits[0].wordpos()); + EXPECT_EQUAL(2u, hits[0].context()); + EXPECT_EQUAL(0u, hits[0].elemId()); + EXPECT_EQUAL(1, hits[0].weight()); + + EXPECT_EQUAL(0u, hits[1].wordpos()); + EXPECT_EQUAL(2u, hits[1].context()); + EXPECT_EQUAL(2u, hits[1].elemId()); + EXPECT_EQUAL(1, hits[1].weight()); + + EXPECT_EQUAL(0u, hits[2].wordpos()); + EXPECT_EQUAL(2u, hits[2].context()); + EXPECT_EQUAL(4u, hits[2].elemId()); + EXPECT_EQUAL(1, hits[2].weight()); + + EXPECT_EQUAL(0u, hits[3].wordpos()); + EXPECT_EQUAL(2u, hits[3].context()); + EXPECT_EQUAL(5u, hits[3].elemId()); + EXPECT_EQUAL(1, hits[3].weight()); + +} + + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/vespa/searchlib/query/query.cpp b/searchlib/src/vespa/searchlib/query/query.cpp index 1cad8a8e41c..c4b49108a7e 100644 --- a/searchlib/src/vespa/searchlib/query/query.cpp +++ b/searchlib/src/vespa/searchlib/query/query.cpp @@ -160,27 +160,23 @@ SameElementQueryNode::evaluateHits(HitList & hl) const unsigned int numFields = size(); unsigned int currMatchCount = 0; std::vector<unsigned int> indexVector(numFields, 0); - auto curr = static_cast<const QueryTerm *> (&(*(*this)[currMatchCount])); + auto curr = static_cast<const QueryTerm *> ((*this)[currMatchCount].get()); bool exhausted( curr->evaluateHits(tmpHL).empty()); for (; !exhausted; ) { - auto next = static_cast<const QueryTerm &>(*(*this)[currMatchCount+1]); + auto next = static_cast<const QueryTerm *>((*this)[currMatchCount+1].get()); unsigned int & currIndex = indexVector[currMatchCount]; unsigned int & nextIndex = indexVector[currMatchCount+1]; const auto & currHit = curr->evaluateHits(tmpHL)[currIndex]; uint32_t currElemId = currHit.elemId(); - uint32_t curContext = currHit.context(); - const HitList & nextHL = next.evaluateHits(tmpHL); + const HitList & nextHL = next->evaluateHits(tmpHL); size_t nextIndexMax = nextHL.size(); - while ((nextIndex < nextIndexMax) && - ((nextHL[nextIndex].context() < curContext) || - ((nextHL[nextIndex].context() == curContext) && (nextHL[nextIndex].elemId() <= currElemId)))) - { + while ((nextIndex < nextIndexMax) && (nextHL[nextIndex].elemId() < currElemId)) { nextIndex++; } - if ((nextHL[nextIndex].context() < curContext) && (nextHL[nextIndex].elemId() == currElemId)) { + if (nextHL[nextIndex].elemId() == currElemId) { currMatchCount++; if ((currMatchCount+1) == numFields) { Hit h = nextHL[indexVector[currMatchCount]]; @@ -192,7 +188,7 @@ SameElementQueryNode::evaluateHits(HitList & hl) const currMatchCount = 0; indexVector[currMatchCount]++; } - curr = static_cast<const QueryTerm *>(&*(*this)[currMatchCount]); + curr = static_cast<const QueryTerm *>((*this)[currMatchCount].get()); exhausted = (nextIndex >= nextIndexMax) || (indexVector[currMatchCount] >= curr->evaluateHits(tmpHL).size()); } return hl; @@ -218,10 +214,10 @@ PhraseQueryNode::evaluateHits(HitList & hl) const unsigned int fullPhraseLen = size(); unsigned int currPhraseLen = 0; std::vector<unsigned int> indexVector(fullPhraseLen, 0); - auto curr = static_cast<const QueryTerm *> (&(*(*this)[currPhraseLen])); + auto curr = static_cast<const QueryTerm *> ((*this)[currPhraseLen].get()); bool exhausted( curr->evaluateHits(tmpHL).empty()); for (; !exhausted; ) { - auto next = static_cast<const QueryTerm &>(*(*this)[currPhraseLen+1]); + auto next = static_cast<const QueryTerm *>((*this)[currPhraseLen+1].get()); unsigned int & currIndex = indexVector[currPhraseLen]; unsigned int & nextIndex = indexVector[currPhraseLen+1]; @@ -230,7 +226,7 @@ PhraseQueryNode::evaluateHits(HitList & hl) const uint32_t currElemId = currHit.elemId(); uint32_t curContext = currHit.context(); - const HitList & nextHL = next.evaluateHits(tmpHL); + const HitList & nextHL = next->evaluateHits(tmpHL); int diff(0); size_t nextIndexMax = nextHL.size(); @@ -246,7 +242,7 @@ PhraseQueryNode::evaluateHits(HitList & hl) const if ((currPhraseLen+1) == fullPhraseLen) { Hit h = nextHL[indexVector[currPhraseLen]]; hl.push_back(h); - const QueryTerm::FieldInfo & fi = next.getFieldInfo(h.context()); + const QueryTerm::FieldInfo & fi = next->getFieldInfo(h.context()); updateFieldInfo(h.context(), hl.size() - 1, fi.getFieldLength()); currPhraseLen = 0; indexVector[0]++; @@ -255,7 +251,7 @@ PhraseQueryNode::evaluateHits(HitList & hl) const currPhraseLen = 0; indexVector[currPhraseLen]++; } - curr = static_cast<const QueryTerm *>(&*(*this)[currPhraseLen]); + curr = static_cast<const QueryTerm *>((*this)[currPhraseLen].get()); exhausted = (nextIndex >= nextIndexMax) || (indexVector[currPhraseLen] >= curr->evaluateHits(tmpHL).size()); } return hl; diff --git a/searchlib/src/vespa/searchlib/query/query.h b/searchlib/src/vespa/searchlib/query/query.h index e96ed9b6bff..b9bcd76d869 100644 --- a/searchlib/src/vespa/searchlib/query/query.h +++ b/searchlib/src/vespa/searchlib/query/query.h @@ -199,6 +199,7 @@ public: size_t width() const; bool valid() const { return _root.get() != NULL; } const QueryNode & getRoot() const { return *_root; } + QueryNode & getRoot() { return *_root; } static QueryNode::UP steal(Query && query) { return std::move(query._root); } private: QueryNode::UP _root; diff --git a/searchlib/src/vespa/searchlib/query/querynode.cpp b/searchlib/src/vespa/searchlib/query/querynode.cpp index 4060033663a..fcc539658d0 100644 --- a/searchlib/src/vespa/searchlib/query/querynode.cpp +++ b/searchlib/src/vespa/searchlib/query/querynode.cpp @@ -72,7 +72,7 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor case ParseItem::ITEM_PURE_WEIGHTED_STRING: case ParseItem::ITEM_PURE_WEIGHTED_LONG: { - vespalib::stringref index = queryRep.getIndexName(); + vespalib::string index = queryRep.getIndexName(); if (index.empty()) { if ((type == ParseItem::ITEM_PURE_WEIGHTED_STRING) || (type == ParseItem::ITEM_PURE_WEIGHTED_LONG)) { index = parent->getIndex(); @@ -80,6 +80,9 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor index = DEFAULT; } } + if (dynamic_cast<const SameElementQueryNode *>(parent) != nullptr) { + index = parent->getIndex() + "." + index; + } vespalib::stringref term = queryRep.getTerm(); QueryTerm::SearchTerm sTerm(QueryTerm::WORD); switch (type) { diff --git a/searchlib/src/vespa/searchlib/query/queryterm.cpp b/searchlib/src/vespa/searchlib/query/queryterm.cpp index 4128629bcf0..ee2e72b41a8 100644 --- a/searchlib/src/vespa/searchlib/query/queryterm.cpp +++ b/searchlib/src/vespa/searchlib/query/queryterm.cpp @@ -73,7 +73,7 @@ QueryTermBase::QueryTermBase() : _termUCS4.push_back(0); } -QueryTermBase::~QueryTermBase() { } +QueryTermBase::~QueryTermBase() = default; QueryTermBase::QueryTermBase(const string & termS, SearchTerm type) : QueryTermSimple(termS, type), @@ -104,7 +104,7 @@ QueryTerm & QueryTerm::operator = (const QueryTerm &) = default; QueryTerm::QueryTerm(QueryTerm &&) = default; QueryTerm & QueryTerm::operator = (QueryTerm &&) = default; -QueryTerm::~QueryTerm() { } +QueryTerm::~QueryTerm() = default; void QueryTermSimple::visitMembers(vespalib::ObjectVisitor & visitor) const @@ -344,7 +344,7 @@ QueryTermSimple::QueryTermSimple() : _diversityAttribute() { } -QueryTermSimple::~QueryTermSimple() { } +QueryTermSimple::~QueryTermSimple() = default; namespace { |