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
Address API review comments.
Kishore Nallan192b00e71fb3
diff --git a/include/collection.h b/include/collection.hindex 6bb74366..83353fc0 100644--- a/include/collection.h+++ b/include/collection.h@@ -92,7 +92,7 @@ public:std::string get_token_ranking_field();- Option<std::string> add(const std::string & json_str);+ Option<nlohmann::json> add(const std::string & json_str);Option<nlohmann::json> search(std::string query, const std::vector<std::string> search_fields,const std::string & simple_filter_query, const std::vector<std::string> & facet_fields,diff --git a/src/api.cpp b/src/api.cppindex 8560064c..1d525e77 100644--- a/src/api.cpp+++ b/src/api.cpp@@ -7,6 +7,28 @@#include "collection.h"#include "collection_manager.h"+nlohmann::json collection_summary_json(Collection *collection) {+ nlohmann::json json_response;++ json_response["name"] = collection->get_name();+ json_response["num_documents"] = collection->get_num_documents();++ const std::vector<field> & coll_fields = collection->get_fields();+ nlohmann::json fields_arr;++ for(const field & coll_field: coll_fields) {+ nlohmann::json field_json;+ field_json[fields::name] = coll_field.name;+ field_json[fields::type] = coll_field.type;+ field_json[fields::facet] = coll_field.facet;+ fields_arr.push_back(field_json);+ }++ json_response["fields"] = fields_arr;+ json_response["token_ranking_field"] = collection->get_token_ranking_field();+ return json_response;+}+bool handle_authentication(const route_path & rpath, const std::string & auth_key) {CollectionManager & collectionManager = CollectionManager::get_instance();if(rpath.handler == get_search) {@@ -19,14 +41,11 @@ bool handle_authentication(const route_path & rpath, const std::string & auth_kevoid get_collections(http_req & req, http_res & res) {CollectionManager & collectionManager = CollectionManager::get_instance();std::vector<Collection*> collections = collectionManager.get_collections();- nlohmann::json json_response;- json_response["data"] = nlohmann::json::array();+ nlohmann::json json_response = nlohmann::json::array();for(Collection* collection: collections) {- nlohmann::json collection_map;- collection_map["name"] = collection->get_name();- collection_map["num_documents"] = collection->get_num_documents();- json_response["collections"].push_back(collection_map);+ nlohmann::json collection_json = collection_summary_json(collection);+ json_response.push_back(collection_json);}res.send_200(json_response.dump());@@ -109,15 +128,16 @@ void del_drop_collection(http_req & req, http_res & res) {std::string doc_id = req.params["id"];CollectionManager & collectionManager = CollectionManager::get_instance();+ Collection* collection = collectionManager.get_collection(req.params["collection"]);+ nlohmann::json collection_json = collection_summary_json(collection);+Option<bool> drop_result = collectionManager.drop_collection(req.params["collection"]);if(!drop_result.ok()) {return res.send(drop_result.code(), drop_result.error());}- nlohmann::json json_response;- json_response["collection"] = req.params["collection"];- res.send_200(json_response.dump());+ res.send_200(collection_json.dump());}void get_search(http_req & req, http_res & res) {@@ -257,25 +277,7 @@ void get_collection_summary(http_req & req, http_res & res) {return res.send_404();}- nlohmann::json json_response;-- json_response["name"] = collection->get_name();- json_response["num_documents"] = collection->get_num_documents();-- const std::vector<field> & coll_fields = collection->get_fields();- nlohmann::json fields_arr;-- for(const field & coll_field: coll_fields) {- nlohmann::json field_json;- field_json[fields::name] = coll_field.name;- field_json[fields::type] = coll_field.type;- field_json[fields::facet] = coll_field.facet;- fields_arr.push_back(field_json);- }-- json_response["fields"] = fields_arr;- json_response["token_ranking_field"] = collection->get_token_ranking_field();-+ nlohmann::json json_response = collection_summary_json(collection);res.send_200(json_response.dump());}@@ -331,14 +333,12 @@ void post_add_document(http_req & req, http_res & res) {return res.send_404();}- Option<std::string> inserted_id_op = collection->add(req.body);+ Option<nlohmann::json> inserted_doc_op = collection->add(req.body);- if(!inserted_id_op.ok()) {- res.send(inserted_id_op.code(), inserted_id_op.error());+ if(!inserted_doc_op.ok()) {+ res.send(inserted_doc_op.code(), inserted_doc_op.error());} else {- nlohmann::json json_response;- json_response["id"] = inserted_id_op.get();- res.send_201(json_response.dump());+ res.send_201(inserted_doc_op.get().dump());}}@@ -369,14 +369,19 @@ void del_remove_document(http_req & req, http_res & res) {return res.send_404();}+ Option<nlohmann::json> doc_option = collection->get(doc_id);++ if(!doc_option.ok()) {+ return res.send(doc_option.code(), doc_option.error());+ }+Option<std::string> deleted_id_op = collection->remove(doc_id);if(!deleted_id_op.ok()) {res.send(deleted_id_op.code(), deleted_id_op.error());} else {- nlohmann::json json_response;- json_response["id"] = deleted_id_op.get();- res.send_200(json_response.dump());+ nlohmann::json doc = doc_option.get();+ res.send_200(doc.dump());}}diff --git a/src/collection.cpp b/src/collection.cppindex 6bcfe60d..1395cd04 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -64,12 +64,12 @@ void Collection::increment_next_seq_id_field() {next_seq_id++;}-Option<std::string> Collection::add(const std::string & json_str) {+Option<nlohmann::json> Collection::add(const std::string & json_str) {nlohmann::json document;try {document = nlohmann::json::parse(json_str);} catch(...) {- return Option<std::string>(400, "Bad JSON.");+ return Option<nlohmann::json>(400, "Bad JSON.");}uint32_t seq_id = get_next_seq_id();@@ -78,7 +78,7 @@ Option<std::string> Collection::add(const std::string & json_str) {if(document.count("id") == 0) {document["id"] = seq_id_str;} else if(!document["id"].is_string()) {- return Option<std::string>(400, "Document's `id` field should be a string.");+ return Option<nlohmann::json>(400, "Document's `id` field should be a string.");}std::string doc_id = document["id"];@@ -86,13 +86,13 @@ Option<std::string> Collection::add(const std::string & json_str) {const Option<uint32_t> & index_memory_op = index_in_memory(document, seq_id);if(!index_memory_op.ok()) {- return Option<std::string>(index_memory_op.code(), index_memory_op.error());+ return Option<nlohmann::json>(index_memory_op.code(), index_memory_op.error());}store->insert(get_doc_id_key(document["id"]), seq_id_str);store->insert(get_seq_id_key(seq_id), document.dump());- return Option<std::string>(doc_id);+ return Option<nlohmann::json>(document);}Option<uint32_t> Collection::validate_index_in_memory(const nlohmann::json &document, uint32_t seq_id) {@@ -503,13 +503,17 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<sstd::string value;store->get(seq_id_key, value);+ nlohmann::json wrapper_doc;nlohmann::json document;+try {document = nlohmann::json::parse(value);} catch(...) {return Option<nlohmann::json>(500, "Error while parsing stored document.");}+ wrapper_doc["document"] = document;+// highlight query words in the resultconst std::string & field_name = search_fields[search_fields.size() - field_order_kv.first];field search_field = search_schema.at(field_name);@@ -576,11 +580,11 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<ssnippet_stream << tokens[snippet_index];}- document["_highlight"] = nlohmann::json::object();- document["_highlight"][field_name] = snippet_stream.str();+ wrapper_doc["_highlight"] = nlohmann::json::object();+ wrapper_doc["_highlight"][field_name] = snippet_stream.str();}- result["hits"].push_back(document);+ result["hits"].push_back(wrapper_doc);}result["facet_counts"] = nlohmann::json::array();diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cppindex 7e0ade1f..31328725 100644--- a/src/main/typesense_server.cpp+++ b/src/main/typesense_server.cpp@@ -31,13 +31,13 @@ void master_server_routes() {server->get("/collections", get_collections);server->del("/collections/:collection", del_drop_collection);server->get("/collections/:collection", get_collection_summary);- server->get("/collections/:collection/export", get_collection_export, true);// document management- server->post("/collections/:collection", post_add_document);- server->get("/collections/:collection/search", get_search);- server->get("/collections/:collection/:id", get_fetch_document);- server->del("/collections/:collection/:id", del_remove_document);+ server->post("/collections/:collection/documents", post_add_document);+ server->get("/collections/:collection/documents/search", get_search);+ server->get("/collections/:collection/documents/:id", get_fetch_document);+ server->get("/collections/:collection/documents/export", get_collection_export, true);+ server->del("/collections/:collection/documents/:id", del_remove_document);// replicationserver->get("/replication/updates", get_replication_updates, true);@@ -47,11 +47,11 @@ void replica_server_routes() {// collection managementserver->get("/collections", get_collections);server->get("/collections/:collection", get_collection_summary);- server->get("/collections/:collection/export", get_collection_export, true);// document management- server->get("/collections/:collection/search", get_search);- server->get("/collections/:collection/:id", get_fetch_document);+ server->get("/collections/:collection/documents/search", get_search);+ server->get("/collections/:collection/documents/:id", get_fetch_document);+ server->get("/collections/:collection/export", get_collection_export, true);// replicationserver->get("/replication/updates", get_replication_updates, true);diff --git a/test/collection_test.cpp b/test/collection_test.cppindex a4c133c8..01ea9885 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -94,7 +94,7 @@ TEST_F(CollectionTest, ExactSearchShouldBeStable) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -110,7 +110,7 @@ TEST_F(CollectionTest, ExactSearchShouldBeStable) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}}@@ -135,7 +135,7 @@ TEST_F(CollectionTest, ExactPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -150,7 +150,7 @@ TEST_F(CollectionTest, ExactPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -164,7 +164,7 @@ TEST_F(CollectionTest, ExactPhraseSearch) {for(size_t i = 0; i < 3; i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}}@@ -180,7 +180,7 @@ TEST_F(CollectionTest, SkipUnindexedTokensDuringPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -191,7 +191,7 @@ TEST_F(CollectionTest, SkipUnindexedTokensDuringPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -203,7 +203,7 @@ TEST_F(CollectionTest, SkipUnindexedTokensDuringPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);std::string id = ids.at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -225,7 +225,7 @@ TEST_F(CollectionTest, PartialPhraseSearch) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -240,7 +240,7 @@ TEST_F(CollectionTest, QueryWithTypo) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -253,7 +253,7 @@ TEST_F(CollectionTest, QueryWithTypo) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -267,7 +267,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -278,7 +278,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -287,7 +287,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 1, 1, FREQUENCY, false).get();ASSERT_EQ(5, results["found"].get<int>());ASSERT_EQ(1, results["hits"].size());- std::string solo_id = results["hits"].at(0)["id"];+ std::string solo_id = results["hits"].at(0)["document"]["id"];ASSERT_STREQ("22", solo_id.c_str());results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 2, 1, FREQUENCY, false).get();@@ -302,7 +302,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -313,7 +313,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -330,7 +330,7 @@ TEST_F(CollectionTest, TextContainingAnActualTypo) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -344,7 +344,7 @@ TEST_F(CollectionTest, TextContainingAnActualTypo) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -359,7 +359,7 @@ TEST_F(CollectionTest, Pagination) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -372,7 +372,7 @@ TEST_F(CollectionTest, Pagination) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -385,7 +385,7 @@ TEST_F(CollectionTest, Pagination) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -399,7 +399,7 @@ TEST_F(CollectionTest, PrefixSearching) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -410,7 +410,7 @@ TEST_F(CollectionTest, PrefixSearching) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -421,7 +421,7 @@ TEST_F(CollectionTest, PrefixSearching) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -433,7 +433,7 @@ TEST_F(CollectionTest, PrefixSearching) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -444,7 +444,7 @@ TEST_F(CollectionTest, PrefixSearching) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -463,7 +463,7 @@ TEST_F(CollectionTest, PrefixSearching) {// prefix with a typoresults = collection->search("late propx", query_fields, "", facets, sort_fields, 2, 1, 1, FREQUENCY, true).get();ASSERT_EQ(1, results["hits"].size());- ASSERT_EQ("16", results["hits"].at(0)["id"]);+ ASSERT_EQ("16", results["hits"].at(0)["document"]["id"]);}TEST_F(CollectionTest, MultipleFields) {@@ -499,7 +499,7 @@ TEST_F(CollectionTest, MultipleFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -514,7 +514,7 @@ TEST_F(CollectionTest, MultipleFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -530,7 +530,7 @@ TEST_F(CollectionTest, MultipleFields) {ids = {"6", "1", "7"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -542,7 +542,7 @@ TEST_F(CollectionTest, MultipleFields) {ids = {"7", "6", "1"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -554,7 +554,7 @@ TEST_F(CollectionTest, MultipleFields) {ids = {"6"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -644,7 +644,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -657,7 +657,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -675,7 +675,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {ids = {"1", "0", "2"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -686,7 +686,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {ids = {"3"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -698,7 +698,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {ids = {"4"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -710,7 +710,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {ids = {"3", "0", "2"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -722,7 +722,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {ids = {"3", "1", "4", "0"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -735,7 +735,7 @@ TEST_F(CollectionTest, FilterOnNumericFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -783,7 +783,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -796,7 +796,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str()); //?}@@ -809,7 +809,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -821,7 +821,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {ids = {"1", "2"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -833,7 +833,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {ids = {"1"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -845,7 +845,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {ids = {"2", "0"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -857,7 +857,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {ids = {"2", "4", "0"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -878,7 +878,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -920,7 +920,7 @@ TEST_F(CollectionTest, SortOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);EXPECT_STREQ(id.c_str(), result_id.c_str());}@@ -933,7 +933,7 @@ TEST_F(CollectionTest, SortOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);EXPECT_STREQ(id.c_str(), result_id.c_str());}@@ -948,7 +948,7 @@ TEST_F(CollectionTest, SortOnFloatFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);EXPECT_STREQ(id.c_str(), result_id.c_str());}@@ -977,7 +977,7 @@ TEST_F(CollectionTest, QueryBoolFields) {std::string json_line;while (std::getline(infile, json_line)) {- Option<std::string> op = coll_bool->add(json_line);+ coll_bool->add(json_line);}infile.close();@@ -992,7 +992,7 @@ TEST_F(CollectionTest, QueryBoolFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1005,7 +1005,7 @@ TEST_F(CollectionTest, QueryBoolFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1017,7 +1017,7 @@ TEST_F(CollectionTest, QueryBoolFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1035,7 +1035,7 @@ TEST_F(CollectionTest, QueryBoolFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1078,7 +1078,7 @@ TEST_F(CollectionTest, FilterOnTextFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1090,7 +1090,7 @@ TEST_F(CollectionTest, FilterOnTextFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1103,7 +1103,7 @@ TEST_F(CollectionTest, FilterOnTextFields) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1297,7 +1297,7 @@ TEST_F(CollectionTest, SortingOrder) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1311,7 +1311,7 @@ TEST_F(CollectionTest, SortingOrder) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1326,7 +1326,7 @@ TEST_F(CollectionTest, SortingOrder) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1341,7 +1341,7 @@ TEST_F(CollectionTest, SortingOrder) {for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);- std::string result_id = result["id"];+ std::string result_id = result["document"]["id"];std::string id = ids.at(i);ASSERT_STREQ(id.c_str(), result_id.c_str());}@@ -1422,23 +1422,23 @@ TEST_F(CollectionTest, IndexingWithBadData) {sample_collection = collectionManager.create_collection("sample_collection", fields, "age").get();}- const Option<std::string> & search_fields_missing_op1 = sample_collection->add("{\"namezz\": \"foo\", \"age\": 29, \"average\": 78}");+ const Option<nlohmann::json> & search_fields_missing_op1 = sample_collection->add("{\"namezz\": \"foo\", \"age\": 29, \"average\": 78}");ASSERT_FALSE(search_fields_missing_op1.ok());ASSERT_STREQ("Field `tags` has been declared in the schema, but is not found in the document.",search_fields_missing_op1.error().c_str());- const Option<std::string> & search_fields_missing_op2 = sample_collection->add("{\"namez\": \"foo\", \"tags\": [], \"age\": 34, \"average\": 78}");+ const Option<nlohmann::json> & search_fields_missing_op2 = sample_collection->add("{\"namez\": \"foo\", \"tags\": [], \"age\": 34, \"average\": 78}");ASSERT_FALSE(search_fields_missing_op2.ok());ASSERT_STREQ("Field `name` has been declared in the schema, but is not found in the document.",search_fields_missing_op2.error().c_str());- const Option<std::string> & facet_fields_missing_op1 = sample_collection->add("{\"name\": \"foo\", \"age\": 34, \"average\": 78}");+ const Option<nlohmann::json> & facet_fields_missing_op1 = sample_collection->add("{\"name\": \"foo\", \"age\": 34, \"average\": 78}");ASSERT_FALSE(facet_fields_missing_op1.ok());ASSERT_STREQ("Field `tags` has been declared in the schema, but is not found in the document.",facet_fields_missing_op1.error().c_str());const char *doc_str = "{\"name\": \"foo\", \"age\": 34, \"avg\": 78, \"tags\": [\"red\", \"blue\"]}";- const Option<std::string> & sort_fields_missing_op1 = sample_collection->add(doc_str);+ const Option<nlohmann::json> & sort_fields_missing_op1 = sample_collection->add(doc_str);ASSERT_FALSE(sort_fields_missing_op1.ok());ASSERT_STREQ("Field `average` has been declared in the schema, but is not found in the document.",sort_fields_missing_op1.error().c_str());@@ -1446,37 +1446,37 @@ TEST_F(CollectionTest, IndexingWithBadData) {// Handle type errorsdoc_str = "{\"name\": \"foo\", \"age\": 34, \"tags\": 22, \"average\": 78}";- const Option<std::string> & bad_facet_field_op = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_facet_field_op = sample_collection->add(doc_str);ASSERT_FALSE(bad_facet_field_op.ok());ASSERT_STREQ("Field `tags` must be a string array.", bad_facet_field_op.error().c_str());doc_str = "{\"name\": \"foo\", \"age\": 34, \"tags\": [], \"average\": 34}";- const Option<std::string> & empty_facet_field_op = sample_collection->add(doc_str);+ const Option<nlohmann::json> & empty_facet_field_op = sample_collection->add(doc_str);ASSERT_TRUE(empty_facet_field_op.ok());doc_str = "{\"name\": \"foo\", \"age\": \"34\", \"tags\": [], \"average\": 34 }";- const Option<std::string> & bad_token_ranking_field_op1 = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_token_ranking_field_op1 = sample_collection->add(doc_str);ASSERT_FALSE(bad_token_ranking_field_op1.ok());ASSERT_STREQ("Token ranking field `age` must be a number.", bad_token_ranking_field_op1.error().c_str());doc_str = "{\"name\": \"foo\", \"age\": 343234324234233234, \"tags\": [], \"average\": 34 }";- const Option<std::string> & bad_token_ranking_field_op2 = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_token_ranking_field_op2 = sample_collection->add(doc_str);ASSERT_FALSE(bad_token_ranking_field_op2.ok());ASSERT_STREQ("Token ranking field `age` exceeds maximum value of int32.", bad_token_ranking_field_op2.error().c_str());doc_str = "{\"name\": \"foo\", \"tags\": [], \"average\": 34 }";- const Option<std::string> & bad_token_ranking_field_op3 = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_token_ranking_field_op3 = sample_collection->add(doc_str);ASSERT_FALSE(bad_token_ranking_field_op3.ok());ASSERT_STREQ("Field `age` has been declared as a token ranking field, but is not found in the document.",bad_token_ranking_field_op3.error().c_str());doc_str = "{\"name\": \"foo\", \"age\": 34, \"tags\": [], \"average\": \"34\"}";- const Option<std::string> & bad_rank_field_op = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_rank_field_op = sample_collection->add(doc_str);ASSERT_FALSE(bad_rank_field_op.ok());ASSERT_STREQ("Field `average` must be an int32.", bad_rank_field_op.error().c_str());doc_str = "{\"name\": \"foo\", \"age\": asdadasd, \"tags\": [], \"average\": 34 }";- const Option<std::string> & bad_token_ranking_field_op4 = sample_collection->add(doc_str);+ const Option<nlohmann::json> & bad_token_ranking_field_op4 = sample_collection->add(doc_str);ASSERT_FALSE(bad_token_ranking_field_op4.ok());ASSERT_STREQ("Bad JSON.", bad_token_ranking_field_op4.error().c_str());@@ -1526,7 +1526,7 @@ TEST_F(CollectionTest, IdFieldShouldBeAString) {doc["tags"] = nlohmann::json::array();doc["tags"].push_back("tag1");- Option<std::string> inserted_id_op = coll1->add(doc.dump());+ Option<nlohmann::json> inserted_id_op = coll1->add(doc.dump());ASSERT_FALSE(inserted_id_op.ok());ASSERT_STREQ("Document's `id` field should be a string.", inserted_id_op.error().c_str());@@ -1551,7 +1551,7 @@ TEST_F(CollectionTest, AnIntegerCanBePassedToAFloatField) {doc["name"] = "Jane";doc["average"] = 98;- Option<std::string> inserted_id_op = coll1->add(doc.dump());+ Option<nlohmann::json> inserted_id_op = coll1->add(doc.dump());EXPECT_TRUE(inserted_id_op.ok());collectionManager.drop_collection("coll1");}