mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
add lazy create index on settings handlers
This commit is contained in:
parent
bfe3bb0eeb
commit
17f71a1a55
@ -192,20 +192,17 @@ async fn update_rules(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Option<Vec<String>>>,
|
body: web::Json<Option<Vec<String>>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
ranking_rules: Some(body.into_inner()),
|
ranking_rules: Some(body.into_inner()),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.to_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data
|
Ok(data
|
||||||
.db
|
.db
|
||||||
.update_write(|w| index.settings_update(w, settings))?;
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -267,20 +264,17 @@ async fn update_distinct(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Option<String>>,
|
body: web::Json<Option<String>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
distinct_attribute: Some(body.into_inner()),
|
distinct_attribute: Some(body.into_inner()),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.to_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data
|
Ok(data
|
||||||
.db
|
.db
|
||||||
.update_write(|w| index.settings_update(w, settings))?;
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -338,11 +332,7 @@ async fn update_searchable(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Option<Vec<String>>>,
|
body: web::Json<Option<Vec<String>>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
searchable_attributes: Some(body.into_inner()),
|
searchable_attributes: Some(body.into_inner()),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
@ -350,9 +340,10 @@ async fn update_searchable(
|
|||||||
|
|
||||||
let settings = settings.to_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
|
|
||||||
let update_id = data
|
Ok(data
|
||||||
.db
|
.db
|
||||||
.update_write(|w| index.settings_update(w, settings))?;
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -412,20 +403,17 @@ async fn update_displayed(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Option<HashSet<String>>>,
|
body: web::Json<Option<HashSet<String>>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
displayed_attributes: Some(body.into_inner()),
|
displayed_attributes: Some(body.into_inner()),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.to_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data
|
Ok(data
|
||||||
.db
|
.db
|
||||||
.update_write(|w| index.settings_update(w, settings))?;
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -494,20 +482,17 @@ async fn update_attributes_for_faceting(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Option<Vec<String>>>,
|
body: web::Json<Option<Vec<String>>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
attributes_for_faceting: Some(body.into_inner()),
|
attributes_for_faceting: Some(body.into_inner()),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let settings = settings.to_update().map_err(Error::bad_request)?;
|
let settings = settings.to_update().map_err(Error::bad_request)?;
|
||||||
let update_id = data
|
Ok(data
|
||||||
.db
|
.db
|
||||||
.update_write(|w| index.settings_update(w, settings))?;
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
|
@ -39,17 +39,16 @@ async fn update(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<BTreeSet<String>>,
|
body: web::Json<BTreeSet<String>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
let settings = SettingsUpdate {
|
||||||
stop_words: UpdateState::Update(body.into_inner()),
|
stop_words: UpdateState::Update(body.into_inner()),
|
||||||
..SettingsUpdate::default()
|
..SettingsUpdate::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
Ok(data
|
||||||
|
.db
|
||||||
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -72,7 +71,9 @@ async fn delete(
|
|||||||
..SettingsUpdate::default()
|
..SettingsUpdate::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data
|
||||||
|
.db
|
||||||
|
.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
|
@ -50,17 +50,16 @@ async fn update(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<BTreeMap<String, Vec<String>>>,
|
body: web::Json<BTreeMap<String, Vec<String>>>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index = data
|
let update_id = data.get_or_create_index(&path.index_uid, |index| {
|
||||||
.db
|
|
||||||
.open_index(&path.index_uid)
|
|
||||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
let settings = SettingsUpdate {
|
||||||
synonyms: UpdateState::Update(body.into_inner()),
|
synonyms: UpdateState::Update(body.into_inner()),
|
||||||
..SettingsUpdate::default()
|
..SettingsUpdate::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
Ok(data
|
||||||
|
.db
|
||||||
|
.update_write(|w| index.settings_update(w, settings))?)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
@ -83,7 +82,9 @@ async fn delete(
|
|||||||
..SettingsUpdate::default()
|
..SettingsUpdate::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let update_id = data.db.update_write(|w| index.settings_update(w, settings))?;
|
let update_id = data
|
||||||
|
.db
|
||||||
|
.update_write(|w| index.settings_update(w, settings))?;
|
||||||
|
|
||||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user