summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/stringattribute
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-21 21:56:55 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-04-22 08:08:05 +0000
commitd5add2f4c82db7088212e550f7c768317f009d53 (patch)
tree34bd3800c03f2720c6750059baea04ffcbb78702 /searchlib/src/tests/attribute/stringattribute
parentb8c7f42862d1557817e1a291bb5f06096afabee8 (diff)
Support both case sensitive, and case-insensitive search in non-fast-search attributes.
Diffstat (limited to 'searchlib/src/tests/attribute/stringattribute')
-rw-r--r--searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
index aaae2772687..ec711b4a456 100644
--- a/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
+++ b/searchlib/src/tests/attribute/stringattribute/stringattribute_test.cpp
@@ -386,6 +386,7 @@ testSingleValue(Attribute & svsa, Config &cfg)
TEST("testSingleValue")
{
EXPECT_EQUAL(24u, sizeof(AttributeVector::SearchContext));
+ EXPECT_EQUAL(24u, sizeof(StringSearchHelper));
EXPECT_EQUAL(56u, sizeof(SingleValueStringAttribute::StringSingleImplSearchContext));
{
Config cfg(BasicType::STRING, CollectionType::SINGLE);
@@ -408,4 +409,83 @@ TEST("testSingleValue")
}
}
+TEST("test uncased match") {
+ QueryTermUCS4 xyz("xyz", QueryTermSimple::Type::WORD);
+ StringSearchHelper helper(xyz, false);
+ EXPECT_FALSE(helper.isCased());
+ EXPECT_FALSE(helper.isPrefix());
+ EXPECT_FALSE(helper.isRegex());
+ EXPECT_FALSE(helper.isMatch("axyz"));
+ EXPECT_FALSE(helper.isMatch("xyza"));
+ EXPECT_TRUE(helper.isMatch("xyz"));
+ EXPECT_TRUE(helper.isMatch("XyZ"));
+}
+
+TEST("test uncased prefix match") {
+ QueryTermUCS4 xyz("xyz", QueryTermSimple::Type::PREFIXTERM);
+ StringSearchHelper helper(xyz, false);
+ EXPECT_FALSE(helper.isCased());
+ EXPECT_TRUE(helper.isPrefix());
+ EXPECT_FALSE(helper.isRegex());
+ EXPECT_FALSE(helper.isMatch("axyz"));
+ EXPECT_TRUE(helper.isMatch("xyza"));
+ EXPECT_TRUE(helper.isMatch("xYza"));
+ EXPECT_TRUE(helper.isMatch("xyz"));
+ EXPECT_TRUE(helper.isMatch("XyZ"));
+}
+
+TEST("test cased match") {
+ QueryTermUCS4 xyz("XyZ", QueryTermSimple::Type::WORD);
+ StringSearchHelper helper(xyz, true);
+ EXPECT_TRUE(helper.isCased());
+ EXPECT_FALSE(helper.isPrefix());
+ EXPECT_FALSE(helper.isRegex());
+ EXPECT_FALSE(helper.isMatch("aXyZ"));
+ EXPECT_FALSE(helper.isMatch("XyZa"));
+ EXPECT_FALSE(helper.isMatch("xyz"));
+ EXPECT_FALSE(helper.isMatch("Xyz"));
+ EXPECT_TRUE(helper.isMatch("XyZ"));
+}
+
+TEST("test cased prefix match") {
+ QueryTermUCS4 xyz("XyZ", QueryTermSimple::Type::PREFIXTERM);
+ StringSearchHelper helper(xyz, true);
+ EXPECT_TRUE(helper.isCased());
+ EXPECT_TRUE(helper.isPrefix());
+ EXPECT_FALSE(helper.isRegex());
+ EXPECT_FALSE(helper.isMatch("aXyZ"));
+ EXPECT_TRUE(helper.isMatch("XyZa"));
+ EXPECT_FALSE(helper.isMatch("xyZa"));
+ EXPECT_FALSE(helper.isMatch("xyz"));
+ EXPECT_FALSE(helper.isMatch("Xyz"));
+ EXPECT_TRUE(helper.isMatch("XyZ"));
+}
+
+TEST("test uncased regex match") {
+ QueryTermUCS4 xyz("x[yY]+Z", QueryTermSimple::Type::REGEXP);
+ StringSearchHelper helper(xyz, false);
+ EXPECT_FALSE(helper.isCased());
+ EXPECT_FALSE(helper.isPrefix());
+ EXPECT_TRUE(helper.isRegex());
+ EXPECT_TRUE(helper.isMatch("axyZ"));
+ EXPECT_TRUE(helper.isMatch("xyZa"));
+ EXPECT_TRUE(helper.isMatch("xyZ"));
+ EXPECT_TRUE(helper.isMatch("xyz"));
+ EXPECT_FALSE(helper.isMatch("xyaZ"));
+}
+
+TEST("test cased regex match") {
+ QueryTermUCS4 xyz("x[Y]+Z", QueryTermSimple::Type::REGEXP);
+ StringSearchHelper helper(xyz, true);
+ EXPECT_TRUE(helper.isCased());
+ EXPECT_FALSE(helper.isPrefix());
+ EXPECT_TRUE(helper.isRegex());
+ EXPECT_TRUE(helper.isMatch("axYZ"));
+ EXPECT_TRUE(helper.isMatch("xYZa"));
+ EXPECT_FALSE(helper.isMatch("xyZ"));
+ EXPECT_TRUE(helper.isMatch("xYZ"));
+ EXPECT_FALSE(helper.isMatch("xYz"));
+ EXPECT_FALSE(helper.isMatch("xaYZ"));
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }