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

Remove redundant string conversion for collection_id.

Kishore Nallan3e8f9298a9b2
diff --git a/TODO.md b/TODO.md
index 9aca740b..bf66be74 100644
--- a/TODO.md
+++ b/TODO.md
@@ -35,7 +35,7 @@
- ~~Have set inside topster itself~~
- Restore records as well on restart (like for meta)
- Persist next_seq_id
-- collection_id should be int, not string
+- ~~collection_id should be int, not string~~
- clean special chars before indexing
**API**
diff --git a/include/collection.h b/include/collection.h
index bb5f5816..0d21f445 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -13,7 +13,7 @@ class Collection {
private:
std::string name;
- std::string collection_id;
+ uint32_t collection_id;
// Auto incrementing record ID used internally for indexing - not exposed to the client
uint32_t next_seq_id;
@@ -56,7 +56,7 @@ private:
public:
Collection() = delete;
- Collection(const std::string name, const std::string collection_id, const uint32_t next_seq_id, Store *store,
+ Collection(const std::string name, const uint32_t collection_id, const uint32_t next_seq_id, Store *store,
const std::vector<field> & search_fields, const std::vector<std::string> & rank_fields);
~Collection();
diff --git a/src/collection.cpp b/src/collection.cpp
index 7c819db5..8f4d5274 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -6,7 +6,7 @@
#include <match_score.h>
#include <string_utils.h>
-Collection::Collection(const std::string name, const std::string collection_id, const uint32_t next_seq_id, Store *store,
+Collection::Collection(const std::string name, const uint32_t collection_id, const uint32_t next_seq_id, Store *store,
const std::vector<field> &search_fields, const std::vector<std::string> & rank_fields):
name(name), collection_id(collection_id), next_seq_id(next_seq_id), store(store), rank_fields(rank_fields) {
diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp
index 63218cc7..dbebb816 100644
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@ -34,7 +34,7 @@ void CollectionManager::init(Store *store) {
}
Collection* collection = new Collection(collection_meta[COLLECTION_NAME_KEY].get<std::string>(),
- std::to_string(collection_meta[COLLECTION_ID_KEY].get<uint32_t>()),
+ collection_meta[COLLECTION_ID_KEY].get<uint32_t>(),
collection_meta[COLLECTION_NEXT_SEQ_ID_KEY].get<uint32_t>(),
store,
search_fields,
@@ -66,8 +66,7 @@ Collection* CollectionManager::create_collection(std::string name, const std::ve
collection_meta[COLLECTION_RANK_FIELDS_KEY] = rank_fields;
store->insert(get_collection_name_key(name), collection_meta.dump());
- std::string collection_id_str = std::to_string(next_collection_id);
- Collection* new_collection = new Collection(name, collection_id_str, 0, store, search_fields, rank_fields);
+ Collection* new_collection = new Collection(name, next_collection_id, 0, store, search_fields, rank_fields);
next_collection_id++;
store->insert(NEXT_COLLECTION_ID_KEY, std::to_string(next_collection_id));