mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
update settings routes
This commit is contained in:
parent
bbf9f41a04
commit
5c49f08bb2
@ -137,9 +137,10 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
|
||||
.delete(|ctx| into_response(setting::delete_displayed(ctx)));
|
||||
});
|
||||
|
||||
router.at("/index-new-fields")
|
||||
.get(|ctx| into_response(setting::get_index_new_fields(ctx)))
|
||||
.post(|ctx| into_response(setting::update_index_new_fields(ctx)));
|
||||
router
|
||||
.at("/index-new-fields")
|
||||
.get(|ctx| into_response(setting::get_index_new_fields(ctx)))
|
||||
.post(|ctx| into_response(setting::update_index_new_fields(ctx)));
|
||||
|
||||
router
|
||||
.at("/synonyms")
|
||||
|
@ -186,43 +186,29 @@ pub async fn delete_ranking(ctx: Request<Data>) -> SResult<Response> {
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct GetRankingRulesSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsRead)?;
|
||||
let index = ctx.index()?;
|
||||
let db = &ctx.state().db;
|
||||
let reader = db.main_read_txn()?;
|
||||
|
||||
let ranking_rules = match index.main.ranking_rules(&reader)? {
|
||||
let ranking_rules: Option<Vec<String>> = match index.main.ranking_rules(&reader)? {
|
||||
Some(rules) => Some(rules.iter().map(|r| r.to_string()).collect()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let settings = GetRankingRulesSettings { ranking_rules };
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SetRankingRulesSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
Ok(tide::Response::new(200).body_json(&ranking_rules).unwrap())
|
||||
}
|
||||
|
||||
pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: SetRankingRulesSettings =
|
||||
let ranking_rules: Option<Vec<String>> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
ranking_rules: settings.ranking_rules,
|
||||
ranking_rules,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
@ -266,9 +252,10 @@ pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||
let reader = db.main_read_txn()?;
|
||||
|
||||
let ranking_distinct = index.main.ranking_distinct(&reader)?;
|
||||
let settings = GetRankingDistinctSettings { ranking_distinct };
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&ranking_distinct)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
@ -280,12 +267,12 @@ pub struct SetRankingDistinctSettings {
|
||||
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: SetRankingDistinctSettings =
|
||||
let ranking_distinct: Option<String> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
ranking_distinct: settings.ranking_distinct,
|
||||
ranking_distinct,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
@ -394,12 +381,6 @@ pub async fn delete_attributes(ctx: Request<Data>) -> SResult<Response> {
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct AttributesIdentifierSettings {
|
||||
pub attribute_identifier: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsRead)?;
|
||||
let index = ctx.index()?;
|
||||
@ -410,17 +391,9 @@ pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let attribute_identifier = schema.map(|s| s.identifier());
|
||||
|
||||
let settings = AttributesIdentifierSettings {
|
||||
attribute_identifier,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct GetAttributesSearchableSettings {
|
||||
pub attributes_searchable: Option<Vec<String>>,
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attribute_identifier)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||
@ -433,11 +406,9 @@ pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let attributes_searchable = schema.map(|s| s.get_indexed_name());
|
||||
|
||||
let settings = GetAttributesSearchableSettings {
|
||||
attributes_searchable,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attributes_searchable)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
@ -449,12 +420,12 @@ pub struct SetAttributesSearchableSettings {
|
||||
pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: SetAttributesSearchableSettings =
|
||||
let attributes_searchable: Option<Vec<String>> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
attributes_searchable: settings.attributes_searchable,
|
||||
attributes_searchable,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
@ -484,12 +455,6 @@ pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct AttributesDisplayedSettings {
|
||||
pub attributes_displayed: Option<HashSet<String>>,
|
||||
}
|
||||
|
||||
pub async fn get_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsRead)?;
|
||||
let index = ctx.index()?;
|
||||
@ -500,22 +465,20 @@ pub async fn get_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let attributes_displayed = schema.map(|s| s.get_displayed_name());
|
||||
|
||||
let settings = AttributesDisplayedSettings {
|
||||
attributes_displayed,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attributes_displayed)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: AttributesDisplayedSettings =
|
||||
let attributes_displayed: Option<HashSet<String>> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
attributes_displayed: settings.attributes_displayed,
|
||||
attributes_displayed,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
@ -545,12 +508,6 @@ pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct IndexNewFieldsSettings {
|
||||
pub index_new_fields: Option<bool>,
|
||||
}
|
||||
|
||||
pub async fn get_index_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsRead)?;
|
||||
let index = ctx.index()?;
|
||||
@ -561,22 +518,20 @@ pub async fn get_index_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
||||
let index_new_fields = schema.map(|s| s.must_index_new_fields());
|
||||
|
||||
let settings = IndexNewFieldsSettings {
|
||||
index_new_fields,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&index_new_fields)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub async fn update_index_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: IndexNewFieldsSettings =
|
||||
let index_new_fields: Option<bool> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
index_new_fields: settings.index_new_fields,
|
||||
index_new_fields,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
|
@ -1273,28 +1273,28 @@ fn search_with_settings_attributes_searchable_2() {
|
||||
|
||||
let query = "q=avangers&limit=3";
|
||||
let response = json!([
|
||||
{
|
||||
"id": 299536,
|
||||
"title": "Avengers: Infinity War",
|
||||
"tagline": "An entire universe. Once and for all.",
|
||||
"overview": "As the Avengers and their allies have continued to protect the world from threats too large for any one hero to handle, a new danger has emerged from the cosmic shadows: Thanos. A despot of intergalactic infamy, his goal is to collect all six Infinity Stones, artifacts of unimaginable power, and use them to inflict his twisted will on all of reality. Everything the Avengers have fought for has led up to this moment - the fate of Earth and existence itself has never been more uncertain.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/7WsyChQLEftFiDOVTGkv3hFpyyt.jpg"
|
||||
},
|
||||
{
|
||||
"id": 299534,
|
||||
"title": "Avengers: Endgame",
|
||||
"tagline": "Part of the journey is the end.",
|
||||
"overview": "After the devastating events of Avengers: Infinity War, the universe is in ruins due to the efforts of the Mad Titan, Thanos. With the help of remaining allies, the Avengers must assemble once more in order to undo Thanos' actions and restore order to the universe once and for all, no matter what consequences may be in store.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/or06FN3Dka5tukK1e9sl16pB3iy.jpg"
|
||||
},
|
||||
{
|
||||
"id": 100402,
|
||||
"title": "Captain America: The Winter Soldier",
|
||||
"tagline": "In heroes we trust.",
|
||||
"overview": "After the cataclysmic events in New York with The Avengers, Steve Rogers, aka Captain America is living quietly in Washington, D.C. and trying to adjust to the modern world. But when a S.H.I.E.L.D. colleague comes under attack, Steve becomes embroiled in a web of intrigue that threatens to put the world at risk. Joining forces with the Black Widow, Captain America struggles to expose the ever-widening conspiracy while fighting off professional assassins sent to silence him at every turn. When the full scope of the villainous plot is revealed, Captain America and the Black Widow enlist the help of a new ally, the Falcon. However, they soon find themselves up against an unexpected and formidable enemy—the Winter Soldier.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/5TQ6YDmymBpnF005OyoB7ohZps9.jpg"
|
||||
}
|
||||
]);
|
||||
{
|
||||
"id": 299536,
|
||||
"title": "Avengers: Infinity War",
|
||||
"tagline": "An entire universe. Once and for all.",
|
||||
"overview": "As the Avengers and their allies have continued to protect the world from threats too large for any one hero to handle, a new danger has emerged from the cosmic shadows: Thanos. A despot of intergalactic infamy, his goal is to collect all six Infinity Stones, artifacts of unimaginable power, and use them to inflict his twisted will on all of reality. Everything the Avengers have fought for has led up to this moment - the fate of Earth and existence itself has never been more uncertain.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/7WsyChQLEftFiDOVTGkv3hFpyyt.jpg"
|
||||
},
|
||||
{
|
||||
"id": 299534,
|
||||
"title": "Avengers: Endgame",
|
||||
"tagline": "Part of the journey is the end.",
|
||||
"overview": "After the devastating events of Avengers: Infinity War, the universe is in ruins due to the efforts of the Mad Titan, Thanos. With the help of remaining allies, the Avengers must assemble once more in order to undo Thanos' actions and restore order to the universe once and for all, no matter what consequences may be in store.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/or06FN3Dka5tukK1e9sl16pB3iy.jpg"
|
||||
},
|
||||
{
|
||||
"id": 100402,
|
||||
"title": "Captain America: The Winter Soldier",
|
||||
"tagline": "In heroes we trust.",
|
||||
"overview": "After the cataclysmic events in New York with The Avengers, Steve Rogers, aka Captain America is living quietly in Washington, D.C. and trying to adjust to the modern world. But when a S.H.I.E.L.D. colleague comes under attack, Steve becomes embroiled in a web of intrigue that threatens to put the world at risk. Joining forces with the Black Widow, Captain America struggles to expose the ever-widening conspiracy while fighting off professional assassins sent to silence him at every turn. When the full scope of the villainous plot is revealed, Captain America and the Black Widow enlist the help of a new ally, the Falcon. However, they soon find themselves up against an unexpected and formidable enemy—the Winter Soldier.",
|
||||
"poster_path": "https://image.tmdb.org/t/p/w500/5TQ6YDmymBpnF005OyoB7ohZps9.jpg"
|
||||
}
|
||||
]);
|
||||
|
||||
common::search(&mut server, query, response);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user