diff --git a/meilisearch-core/src/settings.rs b/meilisearch-core/src/settings.rs index 01790bd8a..d0f9718f5 100644 --- a/meilisearch-core/src/settings.rs +++ b/meilisearch-core/src/settings.rs @@ -26,7 +26,7 @@ pub struct Settings { #[serde(default, deserialize_with = "deserialize_some")] pub synonyms: Option>>>, #[serde(default, deserialize_with = "deserialize_some")] - pub index_new_fields: Option>, + pub accept_new_fields: Option>, } // Any value that is present is considered Some value, including null. @@ -55,7 +55,7 @@ impl Settings { displayed_attributes: settings.displayed_attributes.into(), stop_words: settings.stop_words.into(), synonyms: settings.synonyms.into(), - index_new_fields: settings.index_new_fields.into(), + accept_new_fields: settings.accept_new_fields.into(), }) } } @@ -161,7 +161,7 @@ pub struct SettingsUpdate { pub displayed_attributes: UpdateState>, pub stop_words: UpdateState>, pub synonyms: UpdateState>>, - pub index_new_fields: UpdateState, + pub accept_new_fields: UpdateState, } impl Default for SettingsUpdate { @@ -174,7 +174,7 @@ impl Default for SettingsUpdate { displayed_attributes: UpdateState::Nothing, stop_words: UpdateState::Nothing, synonyms: UpdateState::Nothing, - index_new_fields: UpdateState::Nothing, + accept_new_fields: UpdateState::Nothing, } } } diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index e733adac7..b100ba777 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -68,12 +68,12 @@ pub fn apply_settings_update( UpdateState::Nothing => (), } - match settings.index_new_fields { + match settings.accept_new_fields { UpdateState::Update(v) => { - schema.set_index_new_fields(v); + schema.set_accept_new_fields(v); }, UpdateState::Clear => { - schema.set_index_new_fields(true); + schema.set_accept_new_fields(true); }, UpdateState::Nothing => (), } diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 24e7f2203..a12d226c8 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -101,8 +101,8 @@ pub fn load_routes(app: &mut tide::Server) { .delete(|ctx| into_response(setting::delete_displayed(ctx))); app.at("/indexes/:index/settings/index-new-field") - .get(|ctx| into_response(setting::get_index_new_fields(ctx))) - .post(|ctx| into_response(setting::update_index_new_fields(ctx))); + .get(|ctx| into_response(setting::get_accept_new_fields(ctx))) + .post(|ctx| into_response(setting::update_accept_new_fields(ctx))); app.at("/indexes/:index/settings/synonyms") .get(|ctx| into_response(synonym::get(ctx))) diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 277170fad..b70636217 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -77,7 +77,7 @@ pub async fn get_all(ctx: Request) -> SResult { Some(attrs) } }); - let index_new_fields = schema.map(|s| s.index_new_fields()); + let accept_new_fields = schema.map(|s| s.accept_new_fields()); let settings = Settings { ranking_rules: Some(ranking_rules), @@ -86,7 +86,7 @@ pub async fn get_all(ctx: Request) -> SResult { displayed_attributes, stop_words: Some(stop_words), synonyms: Some(synonyms), - index_new_fields: Some(index_new_fields), + accept_new_fields: Some(accept_new_fields), }; Ok(tide::Response::new(200).body_json(&settings).unwrap()) @@ -102,7 +102,7 @@ pub struct UpdateSettings { pub displayed_attributes: Option>, pub stop_words: Option>, pub synonyms: Option>>, - pub index_new_fields: Option, + pub accept_new_fields: Option, } pub async fn update_all(mut ctx: Request) -> SResult { @@ -119,7 +119,7 @@ pub async fn update_all(mut ctx: Request) -> SResult { displayed_attributes: Some(settings_update.displayed_attributes), stop_words: Some(settings_update.stop_words), synonyms: Some(settings_update.synonyms), - index_new_fields: Some(settings_update.index_new_fields), + accept_new_fields: Some(settings_update.accept_new_fields), }; let mut writer = db.update_write_txn()?; @@ -144,7 +144,7 @@ pub async fn delete_all(ctx: Request) -> SResult { displayed_attributes: UpdateState::Clear, stop_words: UpdateState::Clear, synonyms: UpdateState::Clear, - index_new_fields: UpdateState::Clear, + accept_new_fields: UpdateState::Clear, }; let update_id = index.settings_update(&mut writer, settings)?; @@ -385,7 +385,7 @@ pub async fn delete_displayed(ctx: Request) -> SResult { Ok(tide::Response::new(202).body_json(&response_body)?) } -pub async fn get_index_new_fields(ctx: Request) -> SResult { +pub async fn get_accept_new_fields(ctx: Request) -> SResult { ctx.is_allowed(Private)?; let index = ctx.index()?; let db = &ctx.state().db; @@ -393,22 +393,22 @@ pub async fn get_index_new_fields(ctx: Request) -> SResult { let schema = index.main.schema(&reader)?; - let index_new_fields = schema.map(|s| s.index_new_fields()); + let accept_new_fields = schema.map(|s| s.accept_new_fields()); Ok(tide::Response::new(200) - .body_json(&index_new_fields) + .body_json(&accept_new_fields) .unwrap()) } -pub async fn update_index_new_fields(mut ctx: Request) -> SResult { +pub async fn update_accept_new_fields(mut ctx: Request) -> SResult { ctx.is_allowed(Private)?; let index = ctx.index()?; - let index_new_fields: Option = + let accept_new_fields: Option = ctx.body_json().await.map_err(ResponseError::bad_request)?; let db = &ctx.state().db; let settings = Settings { - index_new_fields: Some(index_new_fields), + accept_new_fields: Some(accept_new_fields), ..Settings::default() }; diff --git a/meilisearch-schema/src/schema.rs b/meilisearch-schema/src/schema.rs index 5a3858f0d..d66693bc9 100644 --- a/meilisearch-schema/src/schema.rs +++ b/meilisearch-schema/src/schema.rs @@ -13,7 +13,7 @@ pub struct Schema { indexed: Vec, indexed_map: HashMap, - index_new_fields: bool, + accept_new_fields: bool, } impl Schema { @@ -28,7 +28,7 @@ impl Schema { displayed: HashSet::new(), indexed: Vec::new(), indexed_map: HashMap::new(), - index_new_fields: true, + accept_new_fields: true, } } @@ -68,7 +68,7 @@ impl Schema { Ok(id) } None => { - if self.index_new_fields { + if self.accept_new_fields { self.set_indexed(name)?; self.set_displayed(name) } else { @@ -190,11 +190,11 @@ impl Schema { Ok(()) } - pub fn index_new_fields(&self) -> bool { - self.index_new_fields + pub fn accept_new_fields(&self) -> bool { + self.accept_new_fields } - pub fn set_index_new_fields(&mut self, value: bool) { - self.index_new_fields = value; + pub fn set_accept_new_fields(&mut self, value: bool) { + self.accept_new_fields = value; } }