aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorAlexey Chernyshev <aleksei@spotify.com>2022-04-04 16:23:07 +0200
committerAlexey Chernyshev <aleksei@spotify.com>2022-04-07 14:44:30 +0200
commit7e9b33401201db9a9e22971dd419247e268bbfaa (patch)
treef5032a82e9fa74247b2fdeb3dcde4dc6cf98ce89 /searchlib/src/tests
parentad7cc1d11f0c19baa2344a643377576c559555f7 (diff)
Propagating annotations for fuzzy query
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp9
-rw-r--r--searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp4
-rw-r--r--searchlib/src/tests/query/customtypevisitor_test.cpp2
-rw-r--r--searchlib/src/tests/query/query_visitor_test.cpp2
-rw-r--r--searchlib/src/tests/query/querybuilder_test.cpp32
-rw-r--r--searchlib/src/tests/query/streaming_query_test.cpp6
6 files changed, 44 insertions, 11 deletions
diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
index aa64e944baa..947e4aa30c2 100644
--- a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
+++ b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
@@ -402,7 +402,8 @@ SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::st
{
uint32_t indexLen = index.size();
uint32_t termLen = term.size();
- uint32_t queryPacketSize = 1 + 2 * 4 + indexLen + termLen;
+ uint32_t fuzzyParametersSize = (termType == TermType::FUZZYTERM) ? 8 : 0;
+ uint32_t queryPacketSize = 1 + 2 * 4 + indexLen + termLen + fuzzyParametersSize;
uint32_t p = 0;
buffer.resize(queryPacketSize);
switch (termType) {
@@ -419,6 +420,12 @@ SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::st
p += vespalib::compress::Integer::compressPositive(termLen, &buffer[p]);
memcpy(&buffer[p], term.c_str(), termLen);
p += termLen;
+
+ if (termType == TermType::FUZZYTERM) {
+ p += vespalib::compress::Integer::compressPositive(2, &buffer[p]); // max edit distance
+ p += vespalib::compress::Integer::compressPositive(0, &buffer[p]); // prefix length
+ }
+
buffer.resize(p);
}
diff --git a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
index 1f570e0a381..4deb287df0e 100644
--- a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
+++ b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
@@ -388,8 +388,8 @@ testSingleValue(Attribute & svsa, Config &cfg)
TEST("testSingleValue")
{
EXPECT_EQUAL(24u, sizeof(SearchContext));
- EXPECT_EQUAL(56u, sizeof(StringSearchHelper));
- EXPECT_EQUAL(104u, sizeof(attribute::SingleStringEnumSearchContext));
+ EXPECT_EQUAL(88u, sizeof(StringSearchHelper));
+ EXPECT_EQUAL(136u, sizeof(attribute::SingleStringEnumSearchContext));
{
Config cfg(BasicType::STRING, CollectionType::SINGLE);
SingleValueStringAttribute svsa("svsa", cfg);
diff --git a/searchlib/src/tests/query/customtypevisitor_test.cpp b/searchlib/src/tests/query/customtypevisitor_test.cpp
index 0e8155e23c3..b1e979b5bcb 100644
--- a/searchlib/src/tests/query/customtypevisitor_test.cpp
+++ b/searchlib/src/tests/query/customtypevisitor_test.cpp
@@ -36,7 +36,7 @@ struct MyRangeTerm : InitTerm<RangeTerm> {};
struct MyStringTerm : InitTerm<StringTerm> {};
struct MySubstrTerm : InitTerm<SubstringTerm> {};
struct MySuffixTerm : InitTerm<SuffixTerm> {};
-struct MyFuzzyTerm : InitTerm<FuzzyTerm> {};
+struct MyFuzzyTerm : FuzzyTerm { MyFuzzyTerm(): FuzzyTerm("term", "view", 0, Weight(0), 2, 0) {} };
struct MyWeakAnd : WeakAnd { MyWeakAnd() : WeakAnd(1234, "view") {} };
struct MyWeightedSetTerm : WeightedSetTerm { MyWeightedSetTerm() : WeightedSetTerm(0, "view", 0, Weight(42)) {} };
struct MyDotProduct : DotProduct { MyDotProduct() : DotProduct(0, "view", 0, Weight(42)) {} };
diff --git a/searchlib/src/tests/query/query_visitor_test.cpp b/searchlib/src/tests/query/query_visitor_test.cpp
index f770213e8e5..8e8be997be0 100644
--- a/searchlib/src/tests/query/query_visitor_test.cpp
+++ b/searchlib/src/tests/query/query_visitor_test.cpp
@@ -86,7 +86,7 @@ TEST("requireThatAllNodesCanBeVisited") {
checkVisit<NearestNeighborTerm>(new SimpleNearestNeighborTerm("query_tensor", "doc_tensor", 0, Weight(0), 123, true, 321, 100100.25));
checkVisit<TrueQueryNode>(new SimpleTrue());
checkVisit<FalseQueryNode>(new SimpleFalse());
- checkVisit<FuzzyTerm>(new SimpleFuzzyTerm("t", "field", 0, Weight(0)));
+ checkVisit<FuzzyTerm>(new SimpleFuzzyTerm("t", "field", 0, Weight(0), 2, 0));
}
} // namespace
diff --git a/searchlib/src/tests/query/querybuilder_test.cpp b/searchlib/src/tests/query/querybuilder_test.cpp
index 2ea566027c4..5b410879fa0 100644
--- a/searchlib/src/tests/query/querybuilder_test.cpp
+++ b/searchlib/src/tests/query/querybuilder_test.cpp
@@ -7,6 +7,8 @@
#include <vespa/searchlib/query/tree/querybuilder.h>
#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/query/tree/stackdumpcreator.h>
+#include <vespa/searchlib/query/query_term_decoder.h>
+#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/log/log.h>
@@ -115,7 +117,7 @@ Node::UP createQueryTree() {
builder.add_true_node();
builder.add_false_node();
}
- builder.addFuzzyTerm(str[5], view[5], id[5], weight[5]);
+ builder.addFuzzyTerm(str[5], view[5], id[5], weight[5], 3, 1);
}
Node::UP node = builder.build();
ASSERT_TRUE(node.get());
@@ -311,6 +313,8 @@ void checkQueryTreeTypes(Node *node) {
auto* fuzzy_term = as_node<FuzzyTerm>(and_node->getChildren()[12]);
EXPECT_TRUE(checkTerm(fuzzy_term, str[5], view[5], id[5], weight[5]));
+ EXPECT_EQUAL(3u, fuzzy_term->getMaxEditDistance());
+ EXPECT_EQUAL(1u, fuzzy_term->getPrefixLength());
}
struct AbstractTypes {
@@ -434,8 +438,9 @@ struct MyNearestNeighborTerm : NearestNeighborTerm {
struct MyTrue : TrueQueryNode {};
struct MyFalse : FalseQueryNode {};
struct MyFuzzyTerm : FuzzyTerm {
- MyFuzzyTerm(const Type &t, const string &f, int32_t i, Weight w)
- : FuzzyTerm(t, f, i, w) {
+ MyFuzzyTerm(const Type &t, const string &f, int32_t i, Weight w,
+ uint32_t m, uint32_t p)
+ : FuzzyTerm(t, f, i, w, m, p) {
}
};
@@ -578,6 +583,7 @@ TEST("require that Query Tree Creator Can Replicate Queries") {
TEST("require that Query Tree Creator Can Create Queries From Stack") {
Node::UP node = createQueryTree<MyQueryNodeTypes>();
string stackDump = StackDumpCreator::create(*node);
+
SimpleQueryStackDumpIterator iterator(stackDump);
Node::UP new_node = QueryTreeCreator<SimpleQueryNodeTypes>::create(iterator);
@@ -618,6 +624,26 @@ TEST("require that All Range Syntaxes Work") {
EXPECT_TRUE(range2 == range_term->getTerm());
}
+TEST("require that fuzzy node can be created") {
+ QueryBuilder<SimpleQueryNodeTypes> builder;
+ builder.addFuzzyTerm("term", "view", 0, Weight(0), 3, 1);
+ Node::UP node = builder.build();
+
+ string stackDump = StackDumpCreator::create(*node);
+ {
+ SimpleQueryStackDumpIterator iterator(stackDump);
+ Node::UP new_node = QueryTreeCreator<SimpleQueryNodeTypes>::create(iterator);
+ FuzzyTerm *fuzzy_node = as_node<FuzzyTerm>(new_node.get());
+ EXPECT_EQUAL(3u, fuzzy_node->getMaxEditDistance());
+ EXPECT_EQUAL(1u, fuzzy_node->getPrefixLength());
+ }
+ {
+ search::QueryTermSimple::UP queryTermSimple = search::QueryTermDecoder::decodeTerm(stackDump);
+ EXPECT_EQUAL(3u, queryTermSimple->getFuzzyMaxEditDistance());
+ EXPECT_EQUAL(1u, queryTermSimple->getFuzzyPrefixLength());
+ }
+}
+
TEST("require that empty intermediate node can be added") {
QueryBuilder<SimpleQueryNodeTypes> builder;
builder.addAnd(0);
diff --git a/searchlib/src/tests/query/streaming_query_test.cpp b/searchlib/src/tests/query/streaming_query_test.cpp
index ec292eda8eb..4b5433dd370 100644
--- a/searchlib/src/tests/query/streaming_query_test.cpp
+++ b/searchlib/src/tests/query/streaming_query_test.cpp
@@ -805,9 +805,9 @@ TEST("testSameElementEvaluate") {
}
TEST("Control the size of query terms") {
- EXPECT_EQUAL(104u, sizeof(QueryTermSimple));
- EXPECT_EQUAL(120u, sizeof(QueryTermUCS4));
- EXPECT_EQUAL(264u, sizeof(QueryTerm));
+ EXPECT_EQUAL(112u, sizeof(QueryTermSimple));
+ EXPECT_EQUAL(128u, sizeof(QueryTermUCS4));
+ EXPECT_EQUAL(272u, sizeof(QueryTerm));
}
TEST_MAIN() { TEST_RUN_ALL(); }