Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Enable num_typos for th locale.

Kishore Nallan63fbf807a9d0
diff --git a/src/index.cpp b/src/index.cpp
index 59ce0078..73b29923 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -2902,7 +2902,7 @@ void Index::fuzzy_search_fields(const std::vector<search_field_t>& the_fields,
int64_t field_num_typos = (field_id < num_typos.size()) ? num_typos[the_field.orig_index] : num_typos[0];
auto& locale = search_schema.at(the_field.name).locale;
- if(locale != "" && locale != "en" && !Tokenizer::is_cyrillic(locale)) {
+ if(locale != "" && locale != "en" && locale != "th" && !Tokenizer::is_cyrillic(locale)) {
// disable fuzzy trie traversal for non-english locales
field_num_typos = 0;
}
diff --git a/test/collection_locale_test.cpp b/test/collection_locale_test.cpp
index 6095a97d..ab40b163 100644
--- a/test/collection_locale_test.cpp
+++ b/test/collection_locale_test.cpp
@@ -278,6 +278,7 @@ TEST_F(CollectionLocaleTest, SearchThaiTextPreSegmentedQuery) {
{"ความเหลื่อมล้ำ", "Compound Word"}, // ความ, เหลื่อม, ล้ำ
{"การกระจายรายได้", "Doc A"},
{"จารีย์", "Doc B"},
+ {"Meiji", "Doc C"},
};
for(size_t i=0; i<records.size(); i++) {
@@ -299,6 +300,24 @@ TEST_F(CollectionLocaleTest, SearchThaiTextPreSegmentedQuery) {
ASSERT_EQ(1, results["found"].get<size_t>());
ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());
+
+ results = coll1->search("meji",
+ {"title"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true},
+ 10, spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 40, {}, {}, {}, 0,
+ "<mark>", "</mark>", {1}, 1000, true, true).get();
+
+ ASSERT_EQ(1, results["found"].get<size_t>());
+ ASSERT_EQ("3", results["hits"][0]["document"]["id"].get<std::string>());
+
+ results = coll1->search("ควม",
+ {"title"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true},
+ 10, spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 40, {}, {}, {}, 0,
+ "<mark>", "</mark>", {1}, 1000, true, true).get();
+
+ ASSERT_EQ(1, results["found"].get<size_t>());
+ ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());
}
TEST_F(CollectionLocaleTest, SearchAgainstThaiTextExactMatch) {