rename ranking_distinct to distinct_attribute; fix #474

This commit is contained in:
qdequele 2020-02-25 16:10:34 +01:00
parent a067a1b16b
commit 2eb6f81c58
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
5 changed files with 25 additions and 25 deletions

View File

@ -16,7 +16,7 @@ pub struct Settings {
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
pub ranking_rules: Option<Option<Vec<String>>>, pub ranking_rules: Option<Option<Vec<String>>>,
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
pub ranking_distinct: Option<Option<String>>, pub distinct_attribute: Option<Option<String>>,
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
pub searchable_attributes: Option<Option<Vec<String>>>, pub searchable_attributes: Option<Option<Vec<String>>>,
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
@ -49,7 +49,7 @@ impl Settings {
Ok(SettingsUpdate { Ok(SettingsUpdate {
ranking_rules, ranking_rules,
ranking_distinct: settings.ranking_distinct.into(), distinct_attribute: settings.distinct_attribute.into(),
identifier: UpdateState::Nothing, identifier: UpdateState::Nothing,
searchable_attributes: settings.searchable_attributes.into(), searchable_attributes: settings.searchable_attributes.into(),
displayed_attributes: settings.displayed_attributes.into(), displayed_attributes: settings.displayed_attributes.into(),
@ -155,7 +155,7 @@ impl RankingRule {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SettingsUpdate { pub struct SettingsUpdate {
pub ranking_rules: UpdateState<Vec<RankingRule>>, pub ranking_rules: UpdateState<Vec<RankingRule>>,
pub ranking_distinct: UpdateState<String>, pub distinct_attribute: UpdateState<String>,
pub identifier: UpdateState<String>, pub identifier: UpdateState<String>,
pub searchable_attributes: UpdateState<Vec<String>>, pub searchable_attributes: UpdateState<Vec<String>>,
pub displayed_attributes: UpdateState<HashSet<String>>, pub displayed_attributes: UpdateState<HashSet<String>>,
@ -168,7 +168,7 @@ impl Default for SettingsUpdate {
fn default() -> Self { fn default() -> Self {
Self { Self {
ranking_rules: UpdateState::Nothing, ranking_rules: UpdateState::Nothing,
ranking_distinct: UpdateState::Nothing, distinct_attribute: UpdateState::Nothing,
identifier: UpdateState::Nothing, identifier: UpdateState::Nothing,
searchable_attributes: UpdateState::Nothing, searchable_attributes: UpdateState::Nothing,
displayed_attributes: UpdateState::Nothing, displayed_attributes: UpdateState::Nothing,

View File

@ -12,7 +12,7 @@ use crate::settings::RankingRule;
const CREATED_AT_KEY: &str = "created-at"; const CREATED_AT_KEY: &str = "created-at";
const RANKING_RULES_KEY: &str = "ranking-rules"; const RANKING_RULES_KEY: &str = "ranking-rules";
const RANKING_DISTINCT_KEY: &str = "ranking-distinct"; const DISTINCT_ATTRIBUTE_KEY: &str = "distinct-attribute";
const STOP_WORDS_KEY: &str = "stop-words"; const STOP_WORDS_KEY: &str = "stop-words";
const SYNONYMS_KEY: &str = "synonyms"; const SYNONYMS_KEY: &str = "synonyms";
const CUSTOMS_KEY: &str = "customs"; const CUSTOMS_KEY: &str = "customs";
@ -200,19 +200,19 @@ impl Main {
self.main.delete::<_, Str>(writer, RANKING_RULES_KEY) self.main.delete::<_, Str>(writer, RANKING_RULES_KEY)
} }
pub fn ranking_distinct(&self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<String>> { pub fn distinct_attribute(&self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<String>> {
if let Some(value) = self.main.get::<_, Str, Str>(reader, RANKING_DISTINCT_KEY)? { if let Some(value) = self.main.get::<_, Str, Str>(reader, DISTINCT_ATTRIBUTE_KEY)? {
return Ok(Some(value.to_owned())) return Ok(Some(value.to_owned()))
} }
return Ok(None) return Ok(None)
} }
pub fn put_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>, value: &str) -> ZResult<()> { pub fn put_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>, value: &str) -> ZResult<()> {
self.main.put::<_, Str, Str>(writer, RANKING_DISTINCT_KEY, value) self.main.put::<_, Str, Str>(writer, DISTINCT_ATTRIBUTE_KEY, value)
} }
pub fn delete_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> { pub fn delete_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
self.main.delete::<_, Str>(writer, RANKING_DISTINCT_KEY) self.main.delete::<_, Str>(writer, DISTINCT_ATTRIBUTE_KEY)
} }
pub fn put_customs(self, writer: &mut heed::RwTxn<MainT>, customs: &[u8]) -> ZResult<()> { pub fn put_customs(self, writer: &mut heed::RwTxn<MainT>, customs: &[u8]) -> ZResult<()> {

View File

@ -58,12 +58,12 @@ pub fn apply_settings_update(
UpdateState::Nothing => (), UpdateState::Nothing => (),
} }
match settings.ranking_distinct { match settings.distinct_attribute {
UpdateState::Update(v) => { UpdateState::Update(v) => {
index.main.put_ranking_distinct(writer, &v)?; index.main.put_distinct_attribute(writer, &v)?;
}, },
UpdateState::Clear => { UpdateState::Clear => {
index.main.delete_ranking_distinct(writer)?; index.main.delete_distinct_attribute(writer)?;
}, },
UpdateState::Nothing => (), UpdateState::Nothing => (),
} }

View File

@ -82,7 +82,7 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
.post(|ctx| into_response(setting::update_rules(ctx))) .post(|ctx| into_response(setting::update_rules(ctx)))
.delete(|ctx| into_response(setting::delete_rules(ctx))); .delete(|ctx| into_response(setting::delete_rules(ctx)));
app.at("/indexes/:index/settings/ranking-distinct") app.at("/indexes/:index/settings/distinct-attribute")
.get(|ctx| into_response(setting::get_distinct(ctx))) .get(|ctx| into_response(setting::get_distinct(ctx)))
.post(|ctx| into_response(setting::update_distinct(ctx))) .post(|ctx| into_response(setting::update_distinct(ctx)))
.delete(|ctx| into_response(setting::delete_distinct(ctx))); .delete(|ctx| into_response(setting::delete_distinct(ctx)));

View File

@ -50,7 +50,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
Some(rules) => Some(rules.iter().map(|r| r.to_string()).collect()), Some(rules) => Some(rules.iter().map(|r| r.to_string()).collect()),
None => None, None => None,
}; };
let ranking_distinct = index.main.ranking_distinct(&reader)?; let distinct_attribute = index.main.distinct_attribute(&reader)?;
let schema = index.main.schema(&reader)?; let schema = index.main.schema(&reader)?;
@ -81,7 +81,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
let settings = Settings { let settings = Settings {
ranking_rules: Some(ranking_rules), ranking_rules: Some(ranking_rules),
ranking_distinct: Some(ranking_distinct), distinct_attribute: Some(distinct_attribute),
searchable_attributes, searchable_attributes,
displayed_attributes, displayed_attributes,
stop_words: Some(stop_words), stop_words: Some(stop_words),
@ -96,7 +96,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
#[serde(rename_all = "camelCase", deny_unknown_fields)] #[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct UpdateSettings { pub struct UpdateSettings {
pub ranking_rules: Option<Vec<String>>, pub ranking_rules: Option<Vec<String>>,
pub ranking_distinct: Option<String>, pub distinct_attribute: Option<String>,
pub identifier: Option<String>, pub identifier: Option<String>,
pub searchable_attributes: Option<Vec<String>>, pub searchable_attributes: Option<Vec<String>>,
pub displayed_attributes: Option<HashSet<String>>, pub displayed_attributes: Option<HashSet<String>>,
@ -114,7 +114,7 @@ pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
let settings = Settings { let settings = Settings {
ranking_rules: Some(settings_update.ranking_rules), ranking_rules: Some(settings_update.ranking_rules),
ranking_distinct: Some(settings_update.ranking_distinct), distinct_attribute: Some(settings_update.distinct_attribute),
searchable_attributes: Some(settings_update.searchable_attributes), searchable_attributes: Some(settings_update.searchable_attributes),
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),
@ -138,7 +138,7 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
let settings = SettingsUpdate { let settings = SettingsUpdate {
ranking_rules: UpdateState::Clear, ranking_rules: UpdateState::Clear,
ranking_distinct: UpdateState::Clear, distinct_attribute: UpdateState::Clear,
identifier: UpdateState::Clear, identifier: UpdateState::Clear,
searchable_attributes: UpdateState::Clear, searchable_attributes: UpdateState::Clear,
displayed_attributes: UpdateState::Clear, displayed_attributes: UpdateState::Clear,
@ -214,22 +214,22 @@ pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
let db = &ctx.state().db; let db = &ctx.state().db;
let reader = db.main_read_txn()?; let reader = db.main_read_txn()?;
let ranking_distinct = index.main.ranking_distinct(&reader)?; let distinct_attribute = index.main.distinct_attribute(&reader)?;
Ok(tide::Response::new(200) Ok(tide::Response::new(200)
.body_json(&ranking_distinct) .body_json(&distinct_attribute)
.unwrap()) .unwrap())
} }
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
ctx.is_allowed(Private)?; ctx.is_allowed(Private)?;
let index = ctx.index()?; let index = ctx.index()?;
let ranking_distinct: Option<String> = let distinct_attribute: Option<String> =
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 {
ranking_distinct: Some(ranking_distinct), distinct_attribute: Some(distinct_attribute),
..Settings::default() ..Settings::default()
}; };
@ -248,7 +248,7 @@ pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let settings = SettingsUpdate { let settings = SettingsUpdate {
ranking_distinct: UpdateState::Clear, distinct_attribute: UpdateState::Clear,
..SettingsUpdate::default() ..SettingsUpdate::default()
}; };