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

Move test to CollectionVectorSearch

ozanarmagan088929d12fb3
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 40b324f4..bb1faa88 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -5216,70 +5216,3 @@ TEST_F(CollectionTest, CatchPartialResponseFromRemoteEmbedding) {
ASSERT_EQ(res["response"]["error"], "Malformed response from OpenAI API.");
ASSERT_EQ(res["request"]["body"], req_body);
}
-
-
-TEST_F(CollectionTest, HybridSearchSortByGeopoint) {
- nlohmann::json schema = R"({
- "name": "objects",
- "fields": [
- {"name": "name", "type": "string"},
- {"name": "location", "type": "geopoint"},
- {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "ts/e5-small"}}}
- ]
- })"_json;
-
-
- auto op = collectionManager.create_collection(schema);
- ASSERT_TRUE(op.ok());
-
- auto coll = op.get();
-
- nlohmann::json doc;
- doc["name"] = "butter";
- doc["location"] = {80.0, 150.0};
-
- auto add_op = coll->add(doc.dump());
-
- ASSERT_TRUE(add_op.ok());
-
- doc["name"] = "butterball";
- doc["location"] = {40.0, 100.0};
-
- add_op = coll->add(doc.dump());
-
- ASSERT_TRUE(add_op.ok());
-
- doc["name"] = "butterfly";
- doc["location"] = {130.0, 200.0};
-
- add_op = coll->add(doc.dump());
-
- ASSERT_TRUE(add_op.ok());
-
-
- spp::sparse_hash_set<std::string> dummy_include_exclude;
-
- std::vector<sort_by> sort_by_list = {{"location(10.0, 10.0)", "asc"}};
-
- auto search_res_op = coll->search("butter", {"name", "embedding"}, "", {}, sort_by_list, {0}, 10, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD, dummy_include_exclude, dummy_include_exclude, 10);
-
- ASSERT_TRUE(search_res_op.ok());
-
- auto search_res = search_res_op.get();
-
- ASSERT_EQ("butterfly", search_res["hits"][0]["document"]["name"].get<std::string>());
- ASSERT_EQ("butterball", search_res["hits"][1]["document"]["name"].get<std::string>());
- ASSERT_EQ("butter", search_res["hits"][2]["document"]["name"].get<std::string>());
-
-
- search_res_op = coll->search("butter", {"name", "embedding"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, Index::DROP_TOKENS_THRESHOLD, dummy_include_exclude, dummy_include_exclude, 10);
-
- ASSERT_TRUE(search_res_op.ok());
-
- search_res = search_res_op.get();
-
-
- ASSERT_EQ("butter", search_res["hits"][0]["document"]["name"].get<std::string>());
- ASSERT_EQ("butterball", search_res["hits"][1]["document"]["name"].get<std::string>());
- ASSERT_EQ("butterfly", search_res["hits"][2]["document"]["name"].get<std::string>());
-}
\ No newline at end of file
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index 2337d967..b726a06a 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -921,3 +921,70 @@ TEST_F(CollectionVectorTest, DistanceThresholdTest) {
ASSERT_FLOAT_EQ(0.8, results_op.get()["hits"][0]["document"]["vec"].get<std::vector<float>>()[2]);
}
+
+
+TEST_F(CollectionVectorTest, HybridSearchSortByGeopoint) {
+ nlohmann::json schema = R"({
+ "name": "objects",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "location", "type": "geopoint"},
+ {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "ts/e5-small"}}}
+ ]
+ })"_json;
+
+
+ auto op = collectionManager.create_collection(schema);
+ ASSERT_TRUE(op.ok());
+
+ auto coll = op.get();
+
+ nlohmann::json doc;
+ doc["name"] = "butter";
+ doc["location"] = {80.0, 150.0};
+
+ auto add_op = coll->add(doc.dump());
+
+ ASSERT_TRUE(add_op.ok());
+
+ doc["name"] = "butterball";
+ doc["location"] = {40.0, 100.0};
+
+ add_op = coll->add(doc.dump());
+
+ ASSERT_TRUE(add_op.ok());
+
+ doc["name"] = "butterfly";
+ doc["location"] = {130.0, 200.0};
+
+ add_op = coll->add(doc.dump());
+
+ ASSERT_TRUE(add_op.ok());
+
+
+ spp::sparse_hash_set<std::string> dummy_include_exclude;
+
+ std::vector<sort_by> sort_by_list = {{"location(10.0, 10.0)", "asc"}};
+
+ auto search_res_op = coll->search("butter", {"name", "embedding"}, "", {}, sort_by_list, {0}, 10, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD, dummy_include_exclude, dummy_include_exclude, 10);
+
+ ASSERT_TRUE(search_res_op.ok());
+
+ auto search_res = search_res_op.get();
+
+ ASSERT_EQ("butterfly", search_res["hits"][0]["document"]["name"].get<std::string>());
+ ASSERT_EQ("butterball", search_res["hits"][1]["document"]["name"].get<std::string>());
+ ASSERT_EQ("butter", search_res["hits"][2]["document"]["name"].get<std::string>());
+
+
+ search_res_op = coll->search("butter", {"name", "embedding"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, Index::DROP_TOKENS_THRESHOLD, dummy_include_exclude, dummy_include_exclude, 10);
+
+ ASSERT_TRUE(search_res_op.ok());
+
+ search_res = search_res_op.get();
+
+
+ ASSERT_EQ("butter", search_res["hits"][0]["document"]["name"].get<std::string>());
+ ASSERT_EQ("butterball", search_res["hits"][1]["document"]["name"].get<std::string>());
+ ASSERT_EQ("butterfly", search_res["hits"][2]["document"]["name"].get<std::string>());
+}
\ No newline at end of file