mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Expose drop colllection API.
This commit is contained in:
parent
c471cd50c3
commit
be0a222ccb
5
TODO.md
5
TODO.md
@ -40,13 +40,16 @@
|
||||
- ~~Snippet should only be around surrounding matching tokens~~
|
||||
- ~~Proper pagination~~
|
||||
- ~~Pagination parameter~~
|
||||
- ~~Drop collection API~~
|
||||
- When prefix=true, use token_ranking_field for token ordering only for last word
|
||||
- Query token ids should match query token ordering
|
||||
- ID should not have "/"
|
||||
- Group results by field
|
||||
- Number of records in collection
|
||||
- Fix API response codes
|
||||
- JSONP response
|
||||
- Use rocksdb batch put for atomic insertion
|
||||
- Handle store-get() not finding a key
|
||||
- Fix API response codes
|
||||
- ~~Test for asc/desc upper/lower casing~~
|
||||
- ~~Test for search without any sort_by given~~
|
||||
- ~~Test for collection creation validation~~
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
void post_create_collection(http_req & req, http_res & res);
|
||||
|
||||
void del_drop_collection(http_req & req, http_res & res);
|
||||
|
||||
void get_search(http_req & req, http_res & res);
|
||||
|
||||
void post_add_document(http_req & req, http_res & res);
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
|
||||
Collection* get_collection(std::string collection_name);
|
||||
|
||||
bool drop_collection(std::string collection_name);
|
||||
Option<bool> drop_collection(std::string collection_name);
|
||||
|
||||
uint32_t get_next_collection_id();
|
||||
|
||||
|
15
src/api.cpp
15
src/api.cpp
@ -115,6 +115,21 @@ void post_create_collection(http_req & req, http_res & res) {
|
||||
res.send_201(req.body);
|
||||
}
|
||||
|
||||
void del_drop_collection(http_req & req, http_res & res) {
|
||||
std::string doc_id = req.params["id"];
|
||||
|
||||
CollectionManager & collectionManager = CollectionManager::get_instance();
|
||||
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());
|
||||
}
|
||||
|
||||
void get_search(http_req & req, http_res & res) {
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
@ -153,10 +153,10 @@ Collection* CollectionManager::get_collection(std::string collection_name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CollectionManager::drop_collection(std::string collection_name) {
|
||||
Option<bool> CollectionManager::drop_collection(std::string collection_name) {
|
||||
Collection* collection = get_collection(collection_name);
|
||||
if(collection == nullptr) {
|
||||
return false;
|
||||
return Option<bool>(404, "No collection with name `" + collection_name + "` found.");
|
||||
}
|
||||
|
||||
store->remove(Collection::get_meta_key(collection_name));
|
||||
@ -176,7 +176,7 @@ bool CollectionManager::drop_collection(std::string collection_name) {
|
||||
delete collection;
|
||||
collection = nullptr;
|
||||
|
||||
return true;
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
uint32_t CollectionManager::get_next_collection_id() {
|
||||
|
@ -19,7 +19,11 @@ int main(int argc, char **argv) {
|
||||
options.get<uint32_t>("listen-port")
|
||||
);
|
||||
|
||||
// collection management
|
||||
server.post("/collection", post_create_collection, true);
|
||||
server.del("/collection/:collection", del_drop_collection, true);
|
||||
|
||||
// document management
|
||||
server.post("/collection/:collection", post_add_document, true);
|
||||
server.get("/collection/:collection/search", get_search, false);
|
||||
server.del("/collection/:collection/:id", del_remove_document, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user