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
Collection summary end-point now shows the schema.
Kishore Nallanbae67169d63c
diff --git a/TODO.md b/TODO.mdindex ed388415..a42d300b 100644--- a/TODO.md+++ b/TODO.md@@ -76,7 +76,7 @@- ~~Validate before string to int conversion in the http api layer~~- ~~art bool support~~- ~~Export collection~~-- get collection should show schema+- ~~get collection should show schema~~- handle hyphens (replace them)- clean special chars before indexing- NOT operator supportdiff --git a/include/collection.h b/include/collection.hindex 879eab8c..f472df08 100644--- a/include/collection.h+++ b/include/collection.h@@ -33,6 +33,8 @@ private:// Auto incrementing record ID used internally for indexing - not exposed to the clientuint32_t next_seq_id;+ std::vector<field> fields;+spp::sparse_hash_map<std::string, field> search_schema;spp::sparse_hash_map<std::string, field> facet_schema;@@ -83,6 +85,8 @@ public:std::vector<field> get_sort_fields();+ std::vector<field> get_fields();+spp::sparse_hash_map<std::string, field> get_schema();std::string get_token_ranking_field();diff --git a/src/api.cpp b/src/api.cppindex a2fab3b5..2f667b35 100644--- a/src/api.cpp+++ b/src/api.cpp@@ -71,8 +71,13 @@ void post_create_collection(http_req & req, http_res & res) {field_json.count(fields::name) == 0 || field_json.count(fields::type) == 0 ||!field_json.at(fields::name).is_string() || !field_json.at(fields::type).is_string()) {- return res.send_400("Wrong format for `fields`. It should be an array like: "- "[{\"name\": \"<field_name>\", \"type\": \"<field_type>\"}]");+ return res.send_400("Wrong format for `fields`. It should be an array of objects containing "+ "`name`, `type` and optionally, `facet` properties.");+ }++ if(field_json.count("facet") != 0 && !field_json.at(fields::facet).is_boolean()) {+ return res.send_400(std::string("The `facet` property of the field `") ++ field_json.at(fields::name).get<std::string>() + "` should be a boolean.");}if(field_json.count("facet") == 0) {@@ -256,6 +261,21 @@ void get_collection_summary(http_req & req, http_res & res) {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["prefix_sort_field"] = collection->get_token_ranking_field();+res.send_200(json_response.dump());}diff --git a/src/collection.cpp b/src/collection.cppindex 19e2e3f3..8eabb432 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -10,7 +10,7 @@Collection::Collection(const std::string name, const uint32_t collection_id, const uint32_t next_seq_id, Store *store,const std::vector<field> &fields, const std::string & token_ranking_field):name(name), collection_id(collection_id), next_seq_id(next_seq_id), store(store),- token_ranking_field(token_ranking_field) {+ fields(fields), token_ranking_field(token_ranking_field) {for(const field& field: fields) {search_schema.emplace(field.name, field);@@ -735,6 +735,10 @@ std::vector<field> Collection::get_sort_fields() {return sort_fields_copy;}+std::vector<field> Collection::get_fields() {+ return fields;+}+spp::sparse_hash_map<std::string, field> Collection::get_schema() {return search_schema;};