mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
rename ranking_distinct to distinct_attribute; fix #474
This commit is contained in:
parent
a067a1b16b
commit
2eb6f81c58
@ -16,7 +16,7 @@ pub struct Settings {
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub ranking_rules: Option<Option<Vec<String>>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub ranking_distinct: Option<Option<String>>,
|
||||
pub distinct_attribute: Option<Option<String>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
pub searchable_attributes: Option<Option<Vec<String>>>,
|
||||
#[serde(default, deserialize_with = "deserialize_some")]
|
||||
@ -49,7 +49,7 @@ impl Settings {
|
||||
|
||||
Ok(SettingsUpdate {
|
||||
ranking_rules,
|
||||
ranking_distinct: settings.ranking_distinct.into(),
|
||||
distinct_attribute: settings.distinct_attribute.into(),
|
||||
identifier: UpdateState::Nothing,
|
||||
searchable_attributes: settings.searchable_attributes.into(),
|
||||
displayed_attributes: settings.displayed_attributes.into(),
|
||||
@ -155,7 +155,7 @@ impl RankingRule {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SettingsUpdate {
|
||||
pub ranking_rules: UpdateState<Vec<RankingRule>>,
|
||||
pub ranking_distinct: UpdateState<String>,
|
||||
pub distinct_attribute: UpdateState<String>,
|
||||
pub identifier: UpdateState<String>,
|
||||
pub searchable_attributes: UpdateState<Vec<String>>,
|
||||
pub displayed_attributes: UpdateState<HashSet<String>>,
|
||||
@ -168,7 +168,7 @@ impl Default for SettingsUpdate {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ranking_rules: UpdateState::Nothing,
|
||||
ranking_distinct: UpdateState::Nothing,
|
||||
distinct_attribute: UpdateState::Nothing,
|
||||
identifier: UpdateState::Nothing,
|
||||
searchable_attributes: UpdateState::Nothing,
|
||||
displayed_attributes: UpdateState::Nothing,
|
||||
|
@ -12,7 +12,7 @@ use crate::settings::RankingRule;
|
||||
|
||||
const CREATED_AT_KEY: &str = "created-at";
|
||||
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 SYNONYMS_KEY: &str = "synonyms";
|
||||
const CUSTOMS_KEY: &str = "customs";
|
||||
@ -200,19 +200,19 @@ impl Main {
|
||||
self.main.delete::<_, Str>(writer, RANKING_RULES_KEY)
|
||||
}
|
||||
|
||||
pub fn ranking_distinct(&self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<String>> {
|
||||
if let Some(value) = self.main.get::<_, Str, Str>(reader, RANKING_DISTINCT_KEY)? {
|
||||
pub fn distinct_attribute(&self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<String>> {
|
||||
if let Some(value) = self.main.get::<_, Str, Str>(reader, DISTINCT_ATTRIBUTE_KEY)? {
|
||||
return Ok(Some(value.to_owned()))
|
||||
}
|
||||
return Ok(None)
|
||||
}
|
||||
|
||||
pub fn put_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>, value: &str) -> ZResult<()> {
|
||||
self.main.put::<_, Str, Str>(writer, RANKING_DISTINCT_KEY, value)
|
||||
pub fn put_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>, value: &str) -> ZResult<()> {
|
||||
self.main.put::<_, Str, Str>(writer, DISTINCT_ATTRIBUTE_KEY, value)
|
||||
}
|
||||
|
||||
pub fn delete_ranking_distinct(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
|
||||
self.main.delete::<_, Str>(writer, RANKING_DISTINCT_KEY)
|
||||
pub fn delete_distinct_attribute(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
|
||||
self.main.delete::<_, Str>(writer, DISTINCT_ATTRIBUTE_KEY)
|
||||
}
|
||||
|
||||
pub fn put_customs(self, writer: &mut heed::RwTxn<MainT>, customs: &[u8]) -> ZResult<()> {
|
||||
|
@ -58,12 +58,12 @@ pub fn apply_settings_update(
|
||||
UpdateState::Nothing => (),
|
||||
}
|
||||
|
||||
match settings.ranking_distinct {
|
||||
match settings.distinct_attribute {
|
||||
UpdateState::Update(v) => {
|
||||
index.main.put_ranking_distinct(writer, &v)?;
|
||||
index.main.put_distinct_attribute(writer, &v)?;
|
||||
},
|
||||
UpdateState::Clear => {
|
||||
index.main.delete_ranking_distinct(writer)?;
|
||||
index.main.delete_distinct_attribute(writer)?;
|
||||
},
|
||||
UpdateState::Nothing => (),
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
|
||||
.post(|ctx| into_response(setting::update_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)))
|
||||
.post(|ctx| into_response(setting::update_distinct(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_distinct(ctx)));
|
||||
|
@ -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()),
|
||||
None => None,
|
||||
};
|
||||
let ranking_distinct = index.main.ranking_distinct(&reader)?;
|
||||
let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
||||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
@ -81,7 +81,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let settings = Settings {
|
||||
ranking_rules: Some(ranking_rules),
|
||||
ranking_distinct: Some(ranking_distinct),
|
||||
distinct_attribute: Some(distinct_attribute),
|
||||
searchable_attributes,
|
||||
displayed_attributes,
|
||||
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)]
|
||||
pub struct UpdateSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
pub ranking_distinct: Option<String>,
|
||||
pub distinct_attribute: Option<String>,
|
||||
pub identifier: Option<String>,
|
||||
pub searchable_attributes: Option<Vec<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 {
|
||||
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),
|
||||
displayed_attributes: Some(settings_update.displayed_attributes),
|
||||
stop_words: Some(settings_update.stop_words),
|
||||
@ -138,7 +138,7 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let settings = SettingsUpdate {
|
||||
ranking_rules: UpdateState::Clear,
|
||||
ranking_distinct: UpdateState::Clear,
|
||||
distinct_attribute: UpdateState::Clear,
|
||||
identifier: UpdateState::Clear,
|
||||
searchable_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 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)
|
||||
.body_json(&ranking_distinct)
|
||||
.body_json(&distinct_attribute)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(Private)?;
|
||||
let index = ctx.index()?;
|
||||
let ranking_distinct: Option<String> =
|
||||
let distinct_attribute: Option<String> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
ranking_distinct: Some(ranking_distinct),
|
||||
distinct_attribute: Some(distinct_attribute),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
@ -248,7 +248,7 @@ pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||
let mut writer = db.update_write_txn()?;
|
||||
|
||||
let settings = SettingsUpdate {
|
||||
ranking_distinct: UpdateState::Clear,
|
||||
distinct_attribute: UpdateState::Clear,
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user