Fix facet index type auto population for wildcard faceting.

This commit is contained in:
Kishore Nallan 2024-05-28 16:03:06 +05:30
parent 3ab8517a8c
commit fdf16b0e23
2 changed files with 37 additions and 2 deletions

View File

@ -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 {

View File

@ -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());
}