replace index_new_fields to accept_new_fields; fix #475

This commit is contained in:
qdequele 2020-02-25 15:51:37 +01:00
parent 1df51c52e0
commit a067a1b16b
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
5 changed files with 27 additions and 27 deletions

View File

@ -26,7 +26,7 @@ pub struct Settings {
#[serde(default, deserialize_with = "deserialize_some")]
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub index_new_fields: Option<Option<bool>>,
pub accept_new_fields: Option<Option<bool>>,
}
// 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<HashSet<String>>,
pub stop_words: UpdateState<BTreeSet<String>>,
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
pub index_new_fields: UpdateState<bool>,
pub accept_new_fields: UpdateState<bool>,
}
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,
}
}
}

View File

@ -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 => (),
}

View File

@ -101,8 +101,8 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
.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)))

View File

@ -77,7 +77,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<HashSet<String>>,
pub stop_words: Option<BTreeSet<String>>,
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
pub index_new_fields: Option<bool>,
pub accept_new_fields: Option<bool>,
}
pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
@ -119,7 +119,7 @@ pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
Ok(tide::Response::new(202).body_json(&response_body)?)
}
pub async fn get_index_new_fields(ctx: Request<Data>) -> SResult<Response> {
pub async fn get_accept_new_fields(ctx: Request<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
pub async fn update_accept_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
ctx.is_allowed(Private)?;
let index = ctx.index()?;
let index_new_fields: Option<bool> =
let accept_new_fields: Option<bool> =
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()
};

View File

@ -13,7 +13,7 @@ pub struct Schema {
indexed: Vec<FieldId>,
indexed_map: HashMap<FieldId, IndexedPos>,
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;
}
}