mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 16:51:01 +00:00
Make possible to use a custom uid and simplify the usage
This commit is contained in:
@ -123,6 +123,7 @@ pub async fn get_index(ctx: Context<Data>) -> SResult<Response> {
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct IndexCreateRequest {
|
||||
name: String,
|
||||
uid: Option<String>,
|
||||
schema: Option<SchemaBody>,
|
||||
}
|
||||
|
||||
@ -148,14 +149,17 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let generated_uid = loop {
|
||||
let uid = generate_uid();
|
||||
if db.open_index(&uid).is_none() {
|
||||
break uid;
|
||||
}
|
||||
let uid = match body.uid {
|
||||
Some(uid) => uid,
|
||||
None => loop {
|
||||
let uid = generate_uid();
|
||||
if db.open_index(&uid).is_none() {
|
||||
break uid;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let created_index = match db.create_index(&generated_uid) {
|
||||
let created_index = match db.create_index(&uid) {
|
||||
Ok(index) => index,
|
||||
Err(e) => return Err(ResponseError::create_index(e)),
|
||||
};
|
||||
@ -189,7 +193,7 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
|
||||
let response_body = IndexCreateResponse {
|
||||
name: body.name,
|
||||
uid: generated_uid,
|
||||
uid,
|
||||
schema: body.schema,
|
||||
update_id: response_update_id,
|
||||
created_at: Utc::now(),
|
||||
|
Reference in New Issue
Block a user