mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
replace index_new_fields to accept_new_fields; fix #475
This commit is contained in:
parent
1df51c52e0
commit
a067a1b16b
@ -26,7 +26,7 @@ pub struct Settings {
|
|||||||
#[serde(default, deserialize_with = "deserialize_some")]
|
#[serde(default, deserialize_with = "deserialize_some")]
|
||||||
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
|
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
|
||||||
#[serde(default, deserialize_with = "deserialize_some")]
|
#[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.
|
// Any value that is present is considered Some value, including null.
|
||||||
@ -55,7 +55,7 @@ impl Settings {
|
|||||||
displayed_attributes: settings.displayed_attributes.into(),
|
displayed_attributes: settings.displayed_attributes.into(),
|
||||||
stop_words: settings.stop_words.into(),
|
stop_words: settings.stop_words.into(),
|
||||||
synonyms: settings.synonyms.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 displayed_attributes: UpdateState<HashSet<String>>,
|
||||||
pub stop_words: UpdateState<BTreeSet<String>>,
|
pub stop_words: UpdateState<BTreeSet<String>>,
|
||||||
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
|
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
|
||||||
pub index_new_fields: UpdateState<bool>,
|
pub accept_new_fields: UpdateState<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SettingsUpdate {
|
impl Default for SettingsUpdate {
|
||||||
@ -174,7 +174,7 @@ impl Default for SettingsUpdate {
|
|||||||
displayed_attributes: UpdateState::Nothing,
|
displayed_attributes: UpdateState::Nothing,
|
||||||
stop_words: UpdateState::Nothing,
|
stop_words: UpdateState::Nothing,
|
||||||
synonyms: UpdateState::Nothing,
|
synonyms: UpdateState::Nothing,
|
||||||
index_new_fields: UpdateState::Nothing,
|
accept_new_fields: UpdateState::Nothing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ pub fn apply_settings_update(
|
|||||||
UpdateState::Nothing => (),
|
UpdateState::Nothing => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match settings.index_new_fields {
|
match settings.accept_new_fields {
|
||||||
UpdateState::Update(v) => {
|
UpdateState::Update(v) => {
|
||||||
schema.set_index_new_fields(v);
|
schema.set_accept_new_fields(v);
|
||||||
},
|
},
|
||||||
UpdateState::Clear => {
|
UpdateState::Clear => {
|
||||||
schema.set_index_new_fields(true);
|
schema.set_accept_new_fields(true);
|
||||||
},
|
},
|
||||||
UpdateState::Nothing => (),
|
UpdateState::Nothing => (),
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
|
|||||||
.delete(|ctx| into_response(setting::delete_displayed(ctx)));
|
.delete(|ctx| into_response(setting::delete_displayed(ctx)));
|
||||||
|
|
||||||
app.at("/indexes/:index/settings/index-new-field")
|
app.at("/indexes/:index/settings/index-new-field")
|
||||||
.get(|ctx| into_response(setting::get_index_new_fields(ctx)))
|
.get(|ctx| into_response(setting::get_accept_new_fields(ctx)))
|
||||||
.post(|ctx| into_response(setting::update_index_new_fields(ctx)));
|
.post(|ctx| into_response(setting::update_accept_new_fields(ctx)));
|
||||||
|
|
||||||
app.at("/indexes/:index/settings/synonyms")
|
app.at("/indexes/:index/settings/synonyms")
|
||||||
.get(|ctx| into_response(synonym::get(ctx)))
|
.get(|ctx| into_response(synonym::get(ctx)))
|
||||||
|
@ -77,7 +77,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
Some(attrs)
|
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 {
|
let settings = Settings {
|
||||||
ranking_rules: Some(ranking_rules),
|
ranking_rules: Some(ranking_rules),
|
||||||
@ -86,7 +86,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
stop_words: Some(stop_words),
|
stop_words: Some(stop_words),
|
||||||
synonyms: Some(synonyms),
|
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())
|
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||||
@ -102,7 +102,7 @@ pub struct UpdateSettings {
|
|||||||
pub displayed_attributes: Option<HashSet<String>>,
|
pub displayed_attributes: Option<HashSet<String>>,
|
||||||
pub stop_words: Option<BTreeSet<String>>,
|
pub stop_words: Option<BTreeSet<String>>,
|
||||||
pub synonyms: Option<BTreeMap<String, Vec<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> {
|
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),
|
displayed_attributes: Some(settings_update.displayed_attributes),
|
||||||
stop_words: Some(settings_update.stop_words),
|
stop_words: Some(settings_update.stop_words),
|
||||||
synonyms: Some(settings_update.synonyms),
|
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()?;
|
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,
|
displayed_attributes: UpdateState::Clear,
|
||||||
stop_words: UpdateState::Clear,
|
stop_words: UpdateState::Clear,
|
||||||
synonyms: UpdateState::Clear,
|
synonyms: UpdateState::Clear,
|
||||||
index_new_fields: UpdateState::Clear,
|
accept_new_fields: UpdateState::Clear,
|
||||||
};
|
};
|
||||||
|
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
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)?)
|
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)?;
|
ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
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 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)
|
Ok(tide::Response::new(200)
|
||||||
.body_json(&index_new_fields)
|
.body_json(&accept_new_fields)
|
||||||
.unwrap())
|
.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)?;
|
ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
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)?;
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
index_new_fields: Some(index_new_fields),
|
accept_new_fields: Some(accept_new_fields),
|
||||||
..Settings::default()
|
..Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ pub struct Schema {
|
|||||||
indexed: Vec<FieldId>,
|
indexed: Vec<FieldId>,
|
||||||
indexed_map: HashMap<FieldId, IndexedPos>,
|
indexed_map: HashMap<FieldId, IndexedPos>,
|
||||||
|
|
||||||
index_new_fields: bool,
|
accept_new_fields: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Schema {
|
impl Schema {
|
||||||
@ -28,7 +28,7 @@ impl Schema {
|
|||||||
displayed: HashSet::new(),
|
displayed: HashSet::new(),
|
||||||
indexed: Vec::new(),
|
indexed: Vec::new(),
|
||||||
indexed_map: HashMap::new(),
|
indexed_map: HashMap::new(),
|
||||||
index_new_fields: true,
|
accept_new_fields: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ impl Schema {
|
|||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if self.index_new_fields {
|
if self.accept_new_fields {
|
||||||
self.set_indexed(name)?;
|
self.set_indexed(name)?;
|
||||||
self.set_displayed(name)
|
self.set_displayed(name)
|
||||||
} else {
|
} else {
|
||||||
@ -190,11 +190,11 @@ impl Schema {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index_new_fields(&self) -> bool {
|
pub fn accept_new_fields(&self) -> bool {
|
||||||
self.index_new_fields
|
self.accept_new_fields
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_index_new_fields(&mut self, value: bool) {
|
pub fn set_accept_new_fields(&mut self, value: bool) {
|
||||||
self.index_new_fields = value;
|
self.accept_new_fields = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user