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

Fix override filter match regression.

Kishore Nallan15dd0626be1c
diff --git a/src/index.cpp b/src/index.cpp
index 6ef2fa70..4fce857d 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -2562,7 +2562,7 @@ bool Index::check_for_overrides(const token_ordering& token_order, const string&
std::vector<sort_by> sort_fields;
std::vector<search_field_t> fq_fields;
- fq_fields.emplace_back(field_name, field_it.value().faceted_name(), 1, 0, true, enable_t::off);
+ fq_fields.emplace_back(field_name, field_it.value().faceted_name(), 1, 0, false, enable_t::off);
uint32_t* filter_ids = nullptr;
filter_result_iterator_t filter_result_it(filter_ids, 0);
@@ -2574,7 +2574,7 @@ bool Index::check_for_overrides(const token_ordering& token_order, const string&
fq_fields, window_tokens, {}, text_match_type_t::max_score, nullptr, 0,
&filter_result_it, {}, {}, sort_fields, {0}, searched_queries,
qtoken_set, topster, groups_processed, result_ids, result_ids_len,
- 0, group_by_fields, false, true, false, false, query_hashes, MAX_SCORE, {true}, 1,
+ 0, group_by_fields, false, true, false, false, query_hashes, MAX_SCORE, {false}, 1,
false, 4, 3, 7, 0, nullptr, field_values, geopoint_indices, "", true);
if(!fuzzy_search_fields_op.ok()) {
diff --git a/test/collection_override_test.cpp b/test/collection_override_test.cpp
index 9f5d1aaf..51dfe1f2 100644
--- a/test/collection_override_test.cpp
+++ b/test/collection_override_test.cpp
@@ -1943,6 +1943,74 @@ TEST_F(CollectionOverrideTest, DynamicFilteringExactMatchBasics) {
collectionManager.drop_collection("coll1");
}
+TEST_F(CollectionOverrideTest, DynamicFilteringPrefixMatchShouldNotWork) {
+ Collection *coll1;
+
+ std::vector<field> fields = {field("name", field_types::STRING, false),
+ field("category", field_types::STRING, true),
+ field("brand", field_types::STRING, true),
+ field("points", field_types::INT32, false)};
+
+ coll1 = collectionManager.get_collection("coll1").get();
+ if(coll1 == nullptr) {
+ coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
+ }
+
+ nlohmann::json doc1;
+ doc1["id"] = "0";
+ doc1["name"] = "Amazing Shoes";
+ doc1["category"] = "shoe";
+ doc1["brand"] = "Nike";
+ doc1["points"] = 3;
+
+ nlohmann::json doc2;
+ doc2["id"] = "1";
+ doc2["name"] = "Track Gym";
+ doc2["category"] = "shoes";
+ doc2["brand"] = "Adidas";
+ doc2["points"] = 5;
+
+ nlohmann::json doc3;
+ doc3["id"] = "2";
+ doc3["name"] = "Running Shoe";
+ doc3["category"] = "shoes";
+ doc3["brand"] = "Nike";
+ doc3["points"] = 5;
+
+ ASSERT_TRUE(coll1->add(doc1.dump()).ok());
+ ASSERT_TRUE(coll1->add(doc2.dump()).ok());
+ ASSERT_TRUE(coll1->add(doc3.dump()).ok());
+
+ std::vector<sort_by> sort_fields = { sort_by("_text_match", "DESC"), sort_by("points", "DESC") };
+
+ // with override, results will be different
+
+ nlohmann::json override_json = {
+ {"id", "dynamic-cat-filter"},
+ {
+ "rule", {
+ {"query", "{category}"},
+ {"match", override_t::MATCH_EXACT}
+ }
+ },
+ {"remove_matched_tokens", true},
+ {"filter_by", "category: {category}"}
+ };
+
+ override_t override;
+ auto op = override_t::parse(override_json, "dynamic-cat-filter", override);
+ ASSERT_TRUE(op.ok());
+ coll1->add_override(override);
+
+ auto results = coll1->search("shoe", {"name", "category", "brand"}, "",
+ {}, sort_fields, {2, 2, 2}, 10).get();
+
+ ASSERT_EQ(1, results["hits"].size());
+ ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());
+
+ collectionManager.drop_collection("coll1");
+}
+
TEST_F(CollectionOverrideTest, DynamicFilteringMissingField) {
Collection *coll1;