aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-10-28 12:16:15 +0200
committerTor Egge <Tor.Egge@online.no>2022-10-28 12:16:15 +0200
commitc1e887cd4d076e61b09966cb78db4e6995b8b60b (patch)
treea66a8f383066e9e602f409c8a55c2dfaad4fd569
parent58e2c2efac9964c14d3c379c38330b0da86ee555 (diff)
Unit test memory index filter search.
-rw-r--r--searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp36
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/fake_result.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/posting_info.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/simpleresult.cpp16
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/simpleresult.h2
5 files changed, 49 insertions, 9 deletions
diff --git a/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp b/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp
index df91dffb3d4..c1261a60278 100644
--- a/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp
+++ b/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp
@@ -16,7 +16,10 @@
#include <vespa/searchlib/queryeval/booleanmatchiteratorwrapper.h>
#include <vespa/searchlib/queryeval/fake_requestcontext.h>
#include <vespa/searchlib/queryeval/fake_searchable.h>
+#include <vespa/searchlib/queryeval/leaf_blueprints.h>
#include <vespa/searchlib/queryeval/searchiterator.h>
+#include <vespa/searchlib/queryeval/simpleresult.h>
+#include <vespa/searchlib/queryeval/simple_phrase_blueprint.h>
#include <vespa/searchlib/queryeval/blueprint.h>
#include <vespa/vespalib/util/sequencedtaskexecutor.h>
#include <vespa/vespalib/util/size_literals.h>
@@ -225,8 +228,10 @@ verifyResult(const FakeResult &expect,
TermFieldMatchData &tmd = *match_data->resolveTermField(handle);
FakeResult actual;
+ SimpleResult exp_simple;
search->initFullRange();
for (search->seek(1); !search->isAtEnd(); search->seek(search->getDocId() + 1)) {
+ exp_simple.addHit(search->getDocId());
actual.doc(search->getDocId());
search->unpack(search->getDocId());
EXPECT_EQ(search->getDocId(), tmd.getDocId());
@@ -236,8 +241,25 @@ verifyResult(const FakeResult &expect,
actual.pos(p.getPosition());
}
}
- EXPECT_EQ(expect, actual);
- return expect == actual;
+ bool success = true;
+ EXPECT_EQ(expect, actual) << (success = false, "");
+ using FilterConstraint = Blueprint::FilterConstraint;
+ for (auto constraint : { FilterConstraint::LOWER_BOUND, FilterConstraint::UPPER_BOUND }) {
+ constexpr uint32_t docid_limit = 10u;
+ auto filter_search = result->createFilterSearch(true, constraint);
+ auto act_simple = SimpleResult().search(*filter_search, docid_limit);
+ if (constraint == FilterConstraint::LOWER_BOUND) {
+ EXPECT_TRUE(exp_simple.contains(act_simple)) << (success = false, "");
+ }
+ if (constraint == FilterConstraint::UPPER_BOUND) {
+ EXPECT_TRUE(act_simple.contains(exp_simple)) << (success = false, "");
+ }
+ if (dynamic_cast<FakeBlueprint*>(result.get()) == nullptr &&
+ dynamic_cast<SimplePhraseBlueprint*>(result.get()) == nullptr) {
+ EXPECT_EQ(exp_simple, act_simple) << (success = false, "");
+ }
+ }
+ return success;
}
namespace {
@@ -246,12 +268,12 @@ SimpleStringTerm makeTerm(const std::string &term) {
}
Node::UP makePhrase(const std::string &term1, const std::string &term2) {
- SimplePhrase * phrase = new SimplePhrase("field", 0, search::query::Weight(0));
- Node::UP node(phrase);
- phrase->append(Node::UP(new SimpleStringTerm(makeTerm(term1))));
- phrase->append(Node::UP(new SimpleStringTerm(makeTerm(term2))));
- return node;
+ auto phrase = std::make_unique<SimplePhrase>("field", 0, search::query::Weight(0));
+ phrase->append(std::make_unique<SimpleStringTerm>(makeTerm(term1)));
+ phrase->append(std::make_unique<SimpleStringTerm>(makeTerm(term2)));
+ return phrase;
}
+
} // namespace
// tests basic usage; index some documents in docid order and perform
diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_result.h b/searchlib/src/vespa/searchlib/queryeval/fake_result.h
index 3c1bad60d8d..3faa30c06bb 100644
--- a/searchlib/src/vespa/searchlib/queryeval/fake_result.h
+++ b/searchlib/src/vespa/searchlib/queryeval/fake_result.h
@@ -95,7 +95,7 @@ public:
}
FakeResult &minMax(int32_t minWeight, int32_t maxWeight) {
- _minMaxPostingInfo.reset(new MinMaxPostingInfo(minWeight, maxWeight));
+ _minMaxPostingInfo = std::make_shared<MinMaxPostingInfo>(minWeight, maxWeight);
return *this;
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/posting_info.h b/searchlib/src/vespa/searchlib/queryeval/posting_info.h
index c3fa5470e48..38503b00306 100644
--- a/searchlib/src/vespa/searchlib/queryeval/posting_info.h
+++ b/searchlib/src/vespa/searchlib/queryeval/posting_info.h
@@ -29,7 +29,7 @@ private:
int32_t _maxWeight;
public:
- MinMaxPostingInfo(int32_t minWeight, int32_t maxWeight)
+ MinMaxPostingInfo(int32_t minWeight, int32_t maxWeight) noexcept
: PostingInfo(),
_minWeight(minWeight),
_maxWeight(maxWeight)
diff --git a/searchlib/src/vespa/searchlib/queryeval/simpleresult.cpp b/searchlib/src/vespa/searchlib/queryeval/simpleresult.cpp
index 75d88ec9428..543f05fa87a 100644
--- a/searchlib/src/vespa/searchlib/queryeval/simpleresult.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/simpleresult.cpp
@@ -62,6 +62,22 @@ SimpleResult::search(SearchIterator &sb, uint32_t docIdLimit)
return *this;
}
+bool
+SimpleResult::contains(const SimpleResult& subset) const
+{
+ auto hits_itr = _hits.begin();
+ for (uint32_t i = 0; i < subset.getHitCount(); ++i) {
+ uint32_t subset_hit = subset.getHit(i);
+ while (hits_itr != _hits.end() && *hits_itr < subset_hit) {
+ ++hits_itr;
+ }
+ if (hits_itr == _hits.end() || *hits_itr > subset_hit) {
+ return false;
+ }
+ }
+ return true;
+}
+
std::ostream &
operator << (std::ostream &out, const SimpleResult &result)
{
diff --git a/searchlib/src/vespa/searchlib/queryeval/simpleresult.h b/searchlib/src/vespa/searchlib/queryeval/simpleresult.h
index 4a8b7a3429f..b3a447156fc 100644
--- a/searchlib/src/vespa/searchlib/queryeval/simpleresult.h
+++ b/searchlib/src/vespa/searchlib/queryeval/simpleresult.h
@@ -83,6 +83,8 @@ public:
* @param rhs other results
**/
bool operator==(const SimpleResult &rhs) const { return (_hits == rhs._hits); }
+
+ bool contains(const SimpleResult& subset) const;
};
std::ostream &operator << (std::ostream &out, const SimpleResult &result);