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_query check with updated facets param

krunal624c6ded2682
diff --git a/src/collection.cpp b/src/collection.cpp
index 112e322c..8a5615b6 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -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);