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

Limit query tokens to 100 bytes.

Kishore Nallan9e505a5322ea
diff --git a/src/collection.cpp b/src/collection.cpp
index c28c2d78..d9fa4d90 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2436,6 +2436,10 @@ void Collection::parse_search_query(const std::string &query, std::vector<std::s
}
for(auto& sub_token: sub_tokens) {
+ if(sub_token.size() > 100) {
+ sub_token.erase(100);
+ }
+
if(exclude_operator_prior) {
if(phrase_search_op_prior) {
phrase.push_back(sub_token);
diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cpp
index 5fc7e353..65a94a71 100644
--- a/test/collection_specific_more_test.cpp
+++ b/test/collection_specific_more_test.cpp
@@ -2058,6 +2058,29 @@ TEST_F(CollectionSpecificMoreTest, DoNotHighlightFieldsForSpecialCharacterQuery)
ASSERT_EQ(0, res["hits"][0]["highlights"].size());
}
+TEST_F(CollectionSpecificMoreTest, SearchForURL) {
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "fields": [
+ {"name": "url", "type": "string"}
+ ]
+ })"_json;
+
+ Collection* coll1 = collectionManager.create_collection(schema).get();
+
+ nlohmann::json doc;
+ doc["url"] = "https://www.cpf.gov.sg/member/infohub/cpf-clarifies/policy-faqs/"
+ "why-interest-earned-on-cpf-life-premium-not-paid-to-beneficiaries";
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ auto res = coll1->search("https://www.cpf.gov.sg/member/infohub/cpf-clarifies/policy-faqs/"
+ "why-interest-earned-on-cpf-life-premium-not-paid-to-beneficiaries", {"url"}, "",
+ {}, {}, {2}, 3, 1,
+ FREQUENCY, {true}).get();
+
+ ASSERT_EQ(1, res["hits"].size());
+}
+
TEST_F(CollectionSpecificMoreTest, CrossFieldTypoAndPrefixWithWeights) {
nlohmann::json schema = R"({
"name": "coll1",