diff --git a/TODO.md b/TODO.md index 57dd05c1..f704c9a8 100644 --- a/TODO.md +++ b/TODO.md @@ -36,6 +36,7 @@ - ~~Facet limit (hardcode to top 10)~~ - ~~Deprecate old split function~~ - ID should not have "/" +- Use rocksdb batch put for atomic insertion - Test for sorted_array::indexOf when length is 0 - Handle store-get() not finding a key - Fix API response codes diff --git a/include/collection.h b/include/collection.h index 4e95bb5f..8bac5741 100644 --- a/include/collection.h +++ b/include/collection.h @@ -62,7 +62,7 @@ private: std::string token_ordering_field; - std::string get_doc_id_key(std::string doc_id); + std::string get_doc_id_key(const std::string & doc_id); std::string get_seq_id_key(uint32_t seq_id); @@ -114,9 +114,9 @@ public: ~Collection(); - static std::string get_next_seq_id_key(std::string collection_name); + static std::string get_next_seq_id_key(const std::string & collection_name); - static std::string get_meta_key(std::string collection_name); + static std::string get_meta_key(const std::string & collection_name); std::string get_seq_id_collection_prefix(); @@ -134,20 +134,20 @@ public: std::string get_token_ordering_field(); - Option add(std::string json_str); + Option add(const std::string & json_str); nlohmann::json search(std::string query, const std::vector search_fields, const std::string & simple_filter_query, const std::vector & facet_fields, const std::vector & sort_fields, const int num_typos, const size_t num_results, const token_ordering token_order = FREQUENCY, const bool prefix = false); - Option remove(std::string id); + Option remove(const std::string & id); void score_results(const std::vector & sort_fields, const int & token_rank, Topster<100> &topster, const std::vector & query_suggestion, const uint32_t *result_ids, const size_t result_size) const; - Option index_in_memory(const nlohmann::json &document, uint32_t seq_id); + Option index_in_memory(const nlohmann::json & document, uint32_t seq_id); enum {MAX_SEARCH_TOKENS = 20}; enum {MAX_RESULTS = 100}; diff --git a/src/collection.cpp b/src/collection.cpp index 2055ef3a..ac220388 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -41,6 +41,7 @@ Collection::~Collection() { for(auto & name_map: sort_index) { delete name_map.second; + name_map.second = nullptr; } } @@ -49,7 +50,7 @@ uint32_t Collection::get_next_seq_id() { return next_seq_id++; } -Option Collection::add(std::string json_str) { +Option Collection::add(const std::string & json_str) { nlohmann::json document = nlohmann::json::parse(json_str); uint32_t seq_id = get_next_seq_id(); @@ -294,7 +295,8 @@ void Collection::index_string_field(const std::string & text, const uint32_t sco } art_insert(t, key, key_len, &art_doc, num_hits); - delete art_doc.offsets; + delete [] art_doc.offsets; + art_doc.offsets = nullptr; } } @@ -996,7 +998,7 @@ void Collection::remove_and_shift_offset_index(sorted_array &offset_index, const delete[] new_array; } -Option Collection::remove(std::string id) { +Option Collection::remove(const std::string & id) { std::string seq_id_str; StoreStatus status = store->get(get_doc_id_key(id), seq_id_str); @@ -1112,7 +1114,7 @@ Option Collection::remove(std::string id) { return Option(id); } -std::string Collection::get_next_seq_id_key(std::string collection_name) { +std::string Collection::get_next_seq_id_key(const std::string & collection_name) { return std::string(COLLECTION_NEXT_SEQ_PREFIX) + "_" + collection_name; } @@ -1127,7 +1129,7 @@ std::string Collection::get_seq_id_key(uint32_t seq_id) { return get_seq_id_collection_prefix() + "_" + std::string(bytes, bytes+4); } -std::string Collection::get_doc_id_key(std::string doc_id) { +std::string Collection::get_doc_id_key(const std::string & doc_id) { return std::to_string(collection_id) + "_" + DOC_ID_PREFIX + doc_id; } @@ -1159,7 +1161,7 @@ spp::sparse_hash_map Collection::get_schema() { return search_schema; }; -std::string Collection::get_meta_key(std::string collection_name) { +std::string Collection::get_meta_key(const std::string & collection_name) { return COLLECTION_META_PREFIX + collection_name; }