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 entry from rocksdb and art when required.

Kishore Nallan596430c03605
diff --git a/TODO.md b/TODO.md
index f36bc15b..5525bba3 100644
--- a/TODO.md
+++ b/TODO.md
@@ -11,12 +11,14 @@
- Facets
- Filters
- Support search operators like +, - etc.
+- ~~Delete should remove from RocksDB~~
+- Speed up UUID generation
**API**
- Support the following operations:
- create a new index
- - index a single document
+ - ~~index a single document~~
- bulk insert multiple documents
- fetch a document by ID
- delete a document by ID
@@ -33,4 +35,4 @@
**Tech debt**
-- Use GLOB file pattern for CMake (better IDE refactoring support)
\ No newline at end of file
+- ~~Use GLOB file pattern for CMake (better IDE refactoring support)~~
\ No newline at end of file
diff --git a/include/store.h b/include/store.h
index 6e4021b0..d5029221 100644
--- a/include/store.h
+++ b/include/store.h
@@ -47,4 +47,9 @@ public:
rocksdb::Status status = db->Get(rocksdb::ReadOptions(), key, &value);
return status.ok();
}
+
+ bool remove(const std::string& key) {
+ rocksdb::Status status = db->Delete(rocksdb::WriteOptions(), key);
+ return status.ok();
+ }
};
\ No newline at end of file
diff --git a/include/string_utils.h b/include/string_utils.h
index 5afc87e1..61f13689 100644
--- a/include/string_utils.h
+++ b/include/string_utils.h
@@ -6,26 +6,27 @@ struct StringUtils {
template<class ContainerT>
static void tokenize(const std::string &str, ContainerT &tokens,
- const std::string &delimiters = " ", bool trimEmpty = false) {
+ const std::string &delimiters = " ", bool trimEmpty = true, unsigned long maxTokenLength = 100) {
+ const std::string truncated_str = str.substr(0, maxTokenLength);
std::string::size_type pos, lastPos = 0;
using value_type = typename ContainerT::value_type;
using size_type = typename ContainerT::size_type;
while (true) {
- pos = str.find_first_of(delimiters, lastPos);
+ pos = truncated_str.find_first_of(delimiters, lastPos);
if (pos == std::string::npos) {
- pos = str.length();
+ pos = truncated_str.length();
if (pos != lastPos || !trimEmpty)
- tokens.push_back(value_type(str.data() + lastPos,
+ tokens.push_back(value_type(truncated_str.data() + lastPos,
(size_type) pos - lastPos));
break;
}
else {
if (pos != lastPos || !trimEmpty)
- tokens.push_back(value_type(str.data() + lastPos,
+ tokens.push_back(value_type(truncated_str.data() + lastPos,
(size_type) pos - lastPos));
}
diff --git a/src/art.cpp b/src/art.cpp
index 993c42db..6178cc43 100644
--- a/src/art.cpp
+++ b/src/art.cpp
@@ -796,6 +796,9 @@ static art_leaf* recursive_delete(art_node *n, art_node **ref, const unsigned ch
return NULL;
}
depth = depth + n->partial_len;
+ if(depth > key_len-1) {
+ return NULL;
+ }
}
// Find child node
diff --git a/src/collection.cpp b/src/collection.cpp
index 7a6bee7e..6045a03a 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -331,6 +331,13 @@ void Collection::remove(std::string id) {
std::cout << "i: " << i << ", val: " << leaf->values->offset_index.at(i) << std::endl;
}
std::cout << "----" << std::endl;*/
+
+ if(leaf->values->ids.getLength() == 0) {
+ art_delete(&t, key, key_len);
+ }
}
}
+
+ store->remove(id);
+ store->remove(seq_id);
}