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 double locking of collection mutex.
Harpreet Sangar82dddd3b6dd4
diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cppindex b25439e6..9f22cdda 100644--- a/test/collection_join_test.cpp+++ b/test/collection_join_test.cpp@@ -710,3 +710,145 @@ TEST_F(CollectionJoinTest, IncludeFieldsByReference_SingleMatch) {// ASSERT_EQ(5, res_obj["hits"][0]["document"].size());// ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_id_sequence_id"));}++TEST_F(CollectionJoinTest, FilterByReferenceField_MultipleMatch) {+ auto schema_json =+ R"({+ "name": "Users",+ "fields": [+ {"name": "user_id", "type": "string"},+ {"name": "user_name", "type": "string"}+ ]+ })"_json;+ std::vector<nlohmann::json> documents = {+ R"({+ "user_id": "user_a",+ "user_name": "Roshan"+ })"_json,+ R"({+ "user_id": "user_b",+ "user_name": "Ruby"+ })"_json,+ R"({+ "user_id": "user_c",+ "user_name": "Joe"+ })"_json,+ R"({+ "user_id": "user_d",+ "user_name": "Aby"+ })"_json+ };+ auto collection_create_op = collectionManager.create_collection(schema_json);+ ASSERT_TRUE(collection_create_op.ok());+ for (auto const &json: documents) {+ auto add_op = collection_create_op.get()->add(json.dump());+ if (!add_op.ok()) {+ LOG(INFO) << add_op.error();+ }+ ASSERT_TRUE(add_op.ok());+ }++ schema_json =+ R"({+ "name": "Repos",+ "fields": [+ {"name": "repo_id", "type": "string"},+ {"name": "repo_content", "type": "string"}+ ]+ })"_json;+ documents = {+ R"({+ "repo_id": "repo_a",+ "repo_content": "body1"+ })"_json,+ R"({+ "repo_id": "repo_b",+ "repo_content": "body2"+ })"_json,+ R"({+ "repo_id": "repo_c",+ "repo_content": "body3"+ })"_json+ };+ collection_create_op = collectionManager.create_collection(schema_json);+ ASSERT_TRUE(collection_create_op.ok());+ for (auto const &json: documents) {+ auto add_op = collection_create_op.get()->add(json.dump());+ if (!add_op.ok()) {+ LOG(INFO) << add_op.error();+ }+ ASSERT_TRUE(add_op.ok());+ }++ schema_json =+ R"({+ "name": "Links",+ "fields": [+ {"name": "repo_id", "type": "string", "reference": "Repos.repo_id"},+ {"name": "user_id", "type": "string", "reference": "Users.user_id"}+ ]+ })"_json;+ documents = {+ R"({+ "repo_id": "repo_a",+ "user_id": "user_b"+ })"_json,+ R"({+ "repo_id": "repo_a",+ "user_id": "user_c"+ })"_json,+ R"({+ "repo_id": "repo_b",+ "user_id": "user_a"+ })"_json,+ R"({+ "repo_id": "repo_b",+ "user_id": "user_b"+ })"_json,+ R"({+ "repo_id": "repo_b",+ "user_id": "user_d"+ })"_json,+ R"({+ "repo_id": "repo_c",+ "user_id": "user_a"+ })"_json,+ R"({+ "repo_id": "repo_c",+ "user_id": "user_b"+ })"_json,+ R"({+ "repo_id": "repo_c",+ "user_id": "user_c"+ })"_json,+ R"({+ "repo_id": "repo_c",+ "user_id": "user_d"+ })"_json+ };+ collection_create_op = collectionManager.create_collection(schema_json);+ ASSERT_TRUE(collection_create_op.ok());++ for (auto const &json: documents) {+ auto add_op = collection_create_op.get()->add(json.dump());+ if (!add_op.ok()) {+ LOG(INFO) << add_op.error();+ }+ ASSERT_TRUE(add_op.ok());+ }++ auto coll = collectionManager.get_collection("Users");++ // Search for users linked to repo_b+ auto result = coll->search("R", {"user_name"}, "$Links(repo_id:=repo_b)", {}, {}, {0},+ 10, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD).get();++ ASSERT_EQ(2, result["found"].get<size_t>());+ ASSERT_EQ(2, result["hits"].size());+ ASSERT_EQ("user_b", result["hits"][0]["document"]["user_id"].get<std::string>());+ ASSERT_EQ("user_a", result["hits"][1]["document"]["user_id"].get<std::string>());++// collectionManager.drop_collection("Users");+// collectionManager.drop_collection("Repos");+// collectionManager.drop_collection("Links");+}\ No newline at end of file