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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix wildcard include/exclude fields not matching `id`.
Harpreet Sangar640987574228
diff --git a/include/collection.h b/include/collection.hindex 030cd319..792e1621 100644--- a/include/collection.h+++ b/include/collection.h@@ -267,7 +267,8 @@ private:std::vector<std::string>& processed_search_fields,bool extract_only_string_fields,bool enable_nested_fields,- const bool handle_wildcard = true);+ const bool handle_wildcard = true,+ const bool& include_id = false);bool is_nested_array(const nlohmann::json& obj, std::vector<std::string> path_parts, size_t part_i) const;diff --git a/src/collection.cpp b/src/collection.cppindex 05ed1149..3464642e 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -1278,7 +1278,8 @@ Option<bool> Collection::extract_field_name(const std::string& field_name,std::vector<std::string>& processed_search_fields,const bool extract_only_string_fields,const bool enable_nested_fields,- const bool handle_wildcard) {+ const bool handle_wildcard,+ const bool& include_id) {// Reference to other collectionif (field_name[0] == '$') {processed_search_fields.push_back(field_name);@@ -1294,6 +1295,12 @@ Option<bool> Collection::extract_field_name(const std::string& field_name,if (is_wildcard && !handle_wildcard) {return Option<bool>(400, "Pattern `" + field_name + "` is not allowed.");}++ if (is_wildcard && include_id && field_name.size() < 4 &&+ (field_name == "*" || field_name == "i*" || field_name == "id*")) {+ processed_search_fields.emplace_back("id");+ }+// If wildcard, remove *auto prefix_it = search_schema.equal_prefix_range(field_name.substr(0, field_name.size() - is_wildcard));bool field_found = false;@@ -5573,7 +5580,7 @@ Option<bool> Collection::populate_include_exclude_fields(const spp::sparse_hash_std::vector<std::string> exclude_fields_vec;for(auto& f_name: include_fields) {- auto field_op = extract_field_name(f_name, search_schema, include_fields_vec, false, enable_nested_fields);+ auto field_op = extract_field_name(f_name, search_schema, include_fields_vec, false, enable_nested_fields, true, true);if(!field_op.ok()) {if(field_op.code() == 404) {// field need not be part of schema to be included (could be a stored value in the doc)@@ -5590,7 +5597,7 @@ Option<bool> Collection::populate_include_exclude_fields(const spp::sparse_hash_continue;}- auto field_op = extract_field_name(f_name, search_schema, exclude_fields_vec, false, enable_nested_fields);+ auto field_op = extract_field_name(f_name, search_schema, exclude_fields_vec, false, enable_nested_fields, true, true);if(!field_op.ok()) {if(field_op.code() == 404) {// field need not be part of schema to be excluded (could be a stored value in the doc)