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 facet index type auto population for wildcard faceting.

Kishore Nallanfdf16b0e23a0
diff --git a/src/collection.cpp b/src/collection.cpp
index eae5ab50..9d09dd74 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2113,7 +2113,7 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
std::vector<std::string> facet_index_str_types;
StringUtils::split(facet_index_type, facet_index_str_types, ",");
if(facet_index_str_types.empty()) {
- for(size_t i = 0; i < facet_fields.size(); i++) {
+ for(size_t i = 0; i < facets.size(); i++) {
facet_index_types.push_back(automatic);
}
} else if(facet_index_str_types.size() == 1) {
@@ -2121,7 +2121,7 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
if(!match_op.has_value()) {
return Option<nlohmann::json>(400, "Invalid facet index type: " + facet_index_str_types[0]);
}
- for(size_t i = 0; i < facet_fields.size(); i++) {
+ for(size_t i = 0; i < facets.size(); i++) {
facet_index_types.push_back(match_op.value());
}
} else {
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp
index bee3158f..3882ffaa 100644
--- a/test/collection_faceting_test.cpp
+++ b/test/collection_faceting_test.cpp
@@ -3226,3 +3226,38 @@ TEST_F(CollectionFacetingTest, RangeFacetsWithSortDisabled) {
ASSERT_FALSE(results.ok());
ASSERT_EQ("Range facets require sort enabled for the field.", results.error());
}
+
+TEST_F(CollectionFacetingTest, FacetSearchIndexTypeValidation) {
+ std::vector<field> fields = {
+ field("attribute.title", field_types::STRING, true),
+ field("attribute.category", field_types::STRING, true),
+ };
+
+ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields).get();
+ nlohmann::json doc;
+ doc["attribute.title"] = "Foobar";
+ doc["attribute.category"] = "shoes";
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ auto res_op = coll1->search("*", {},
+ "", {"attribute.*"}, {}, {2}, 1, 1, FREQUENCY, {true}, 1,
+ spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 5, "", 30, 4, "", 20, {}, {}, {}, 0,
+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7,
+ fallback,
+ 4, {off}, 3, 3, 2, 2, false, "", true, 0, max_score, 100, 0, 4294967295UL,
+ "top_values");
+
+ ASSERT_TRUE(res_op.ok());
+
+ res_op = coll1->search("*", {},
+ "", {"attribute.*"}, {}, {2}, 1, 1, FREQUENCY, {true}, 1,
+ spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 5, "", 30, 4, "", 20, {}, {}, {}, 0,
+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7,
+ fallback,
+ 4, {off}, 3, 3, 2, 2, false, "", true, 0, max_score, 100, 0, 4294967295UL,
+ "");
+
+ ASSERT_TRUE(res_op.ok());
+}