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
Don't allow field with same name as regexp field pattern.
Kishore Nallane68458aff382
diff --git a/include/field.h b/include/field.hindex fcd1cea0..4c63bd63 100644--- a/include/field.h+++ b/include/field.h@@ -116,6 +116,10 @@ struct field {return (type == field_types::STRING || type == field_types::STRING_ARRAY);}+ bool is_string_star() const {+ return field_types::is_string_or_array(type);+ }+bool is_facet() const {return facet;}diff --git a/src/collection.cpp b/src/collection.cppindex 8596f2a6..7c8d1847 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -269,10 +269,9 @@ nlohmann::json Collection::add_many(std::vector<std::string>& json_lines, nlohmaauto persist_op = persist_collection_meta();if(!persist_op.ok()) {record.index_failure(persist_op.code(), persist_op.error());- continue;+ } else {+ index->refresh_schemas(new_fields, {});}-- index->refresh_schemas(new_fields, {});}}}@@ -2968,6 +2967,12 @@ Option<bool> Collection::detect_new_fields(nlohmann::json& document,// check against dynamic field definitionsfor(const auto& dynamic_field: dyn_fields) {if(std::regex_match (kv.key(), std::regex(dynamic_field.first))) {+ // unless the field is auto or string*, ignore field name matching regexp pattern+ if(kv.key() == dynamic_field.first && !dynamic_field.second.is_auto() &&+ !dynamic_field.second.is_string_star()) {+ continue;+ }+new_field = dynamic_field.second;new_field.name = fname;found_dynamic_field = true;diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cppindex ccfb9669..80137d39 100644--- a/test/collection_all_fields_test.cpp+++ b/test/collection_all_fields_test.cpp@@ -1505,3 +1505,33 @@ TEST_F(CollectionAllFieldsTest, SchemaUpdateShouldBeAtomicForAllFields) {collectionManager.drop_collection("coll1");}++TEST_F(CollectionAllFieldsTest, FieldNameMatchingRegexpShouldNotBeIndexed) {+ std::vector<field> fields = {field("title", field_types::STRING, false),+ field("name.*", field_types::STRING, true, true)};++ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields).get();++ nlohmann::json doc1;+ doc1["id"] = "0";+ doc1["title"] = "One Two Three";+ doc1["name.*"] = "Rowling";++ std::vector<std::string> json_lines;+ json_lines.push_back(doc1.dump());++ coll1->add_many(json_lines, doc1, UPSERT);+ coll1->add_many(json_lines, doc1, UPSERT);++ ASSERT_EQ(1, coll1->_get_index()->_get_search_index().size());++ auto results = coll1->search("one", {"title"},+ "", {}, {}, {2}, 10,+ 1, FREQUENCY, {true},+ 1, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "title", 5, {}, {}, {}, 0,+ "<mark>", "</mark>", {}, 1000, true).get();++ ASSERT_EQ(1, results["hits"].size());+}+diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cppindex ba8e1d1e..0a36fae0 100644--- a/test/collection_specific_more_test.cpp+++ b/test/collection_specific_more_test.cpp@@ -160,7 +160,6 @@ TEST_F(CollectionSpecificMoreTest, MatchedSegmentMoreImportantThanTotalMatches)spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "title", 5, {}, {}, {}, 0,"<mark>", "</mark>", {}, 1000, true).get();- LOG(INFO) << results;ASSERT_EQ(3, results["hits"].size());ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());