fix facet_query check with updated facets param

This commit is contained in:
krunal 2023-10-26 13:55:12 +05:30
parent 976d62657f
commit 624c6ded26

View File

@ -1800,7 +1800,14 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
} else {
// facet query field must be part of facet fields requested
facet_query = { StringUtils::trim(facet_query_fname), facet_query_value };
if(std::find(facet_fields.begin(), facet_fields.end(), facet_query.field_name) == facet_fields.end()) {
bool found = false;
for(const auto& facet : facets) {
if(facet.field_name == facet_query.field_name) {
found=true;
break;
}
}
if(!found) {
std::string error = "Facet query refers to a facet field `" + facet_query.field_name + "` " +
"that is not part of `facet_by` parameter.";
return Option<nlohmann::json>(400, error);