mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 00:55:00 +08:00
global settings update make partial update; fix #516
This commit is contained in:
parent
ce0e8415d5
commit
7be376721c
@ -1,5 +1,4 @@
|
|||||||
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState, DEFAULT_RANKING_RULES};
|
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState, DEFAULT_RANKING_RULES};
|
||||||
use serde::Deserialize;
|
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||||
use tide::{Request, Response};
|
use tide::{Request, Response};
|
||||||
|
|
||||||
@ -73,36 +72,13 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
||||||
pub struct UpdateSettings {
|
|
||||||
pub ranking_rules: Option<Vec<String>>,
|
|
||||||
pub distinct_attribute: Option<String>,
|
|
||||||
pub primary_key: Option<String>,
|
|
||||||
pub searchable_attributes: Option<Vec<String>>,
|
|
||||||
pub displayed_attributes: Option<HashSet<String>>,
|
|
||||||
pub stop_words: Option<BTreeSet<String>>,
|
|
||||||
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
|
|
||||||
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> {
|
||||||
ctx.is_allowed(Private)?;
|
ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
let index = ctx.index()?;
|
||||||
let settings_update: UpdateSettings =
|
let settings: Settings =
|
||||||
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 {
|
|
||||||
ranking_rules: Some(settings_update.ranking_rules),
|
|
||||||
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),
|
|
||||||
synonyms: Some(settings_update.synonyms),
|
|
||||||
accept_new_fields: Some(settings_update.accept_new_fields),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
|
@ -644,7 +644,6 @@ fn search_with_settings_basic() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"tagline",
|
"tagline",
|
||||||
@ -751,7 +750,6 @@ fn search_with_settings_stop_words() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"tagline",
|
"tagline",
|
||||||
@ -858,7 +856,6 @@ fn search_with_settings_synonyms() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"tagline",
|
"tagline",
|
||||||
@ -970,7 +967,6 @@ fn search_with_settings_ranking_rules() {
|
|||||||
"desc(popularity)"
|
"desc(popularity)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"tagline",
|
"tagline",
|
||||||
@ -1077,7 +1073,6 @@ fn search_with_settings_searchable_attributes() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"tagline",
|
"tagline",
|
||||||
"overview",
|
"overview",
|
||||||
@ -1183,7 +1178,6 @@ fn search_with_settings_displayed_attributes() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"tagline",
|
"tagline",
|
||||||
@ -1254,7 +1248,6 @@ fn search_with_settings_searchable_attributes_2() {
|
|||||||
"desc(vote_average)"
|
"desc(vote_average)"
|
||||||
],
|
],
|
||||||
"distinctAttribute": null,
|
"distinctAttribute": null,
|
||||||
"primaryKey": "id",
|
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"tagline",
|
"tagline",
|
||||||
"overview",
|
"overview",
|
||||||
|
@ -192,6 +192,7 @@ fn write_all_and_update() {
|
|||||||
"exactness",
|
"exactness",
|
||||||
"desc(release_date)",
|
"desc(release_date)",
|
||||||
],
|
],
|
||||||
|
"distinctAttribute": null,
|
||||||
"searchableAttributes": [
|
"searchableAttributes": [
|
||||||
"title",
|
"title",
|
||||||
"description",
|
"description",
|
||||||
@ -204,8 +205,7 @@ fn write_all_and_update() {
|
|||||||
"rank",
|
"rank",
|
||||||
"poster",
|
"poster",
|
||||||
],
|
],
|
||||||
"stopWords": [
|
"stopWords": [],
|
||||||
],
|
|
||||||
"synonyms": {
|
"synonyms": {
|
||||||
"wolverine": ["xmen", "logan"],
|
"wolverine": ["xmen", "logan"],
|
||||||
"logan": ["wolverine", "xmen"],
|
"logan": ["wolverine", "xmen"],
|
||||||
@ -321,3 +321,111 @@ fn test_default_settings_2() {
|
|||||||
|
|
||||||
assert_json_eq!(body, response, ordered: false);
|
assert_json_eq!(body, response, ordered: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/516
|
||||||
|
#[test]
|
||||||
|
fn write_setting_and_update_partial() {
|
||||||
|
let mut server = common::Server::with_uid("movies");
|
||||||
|
let body = json!({
|
||||||
|
"uid": "movies",
|
||||||
|
});
|
||||||
|
server.create_index(body);
|
||||||
|
|
||||||
|
// 2 - Send the settings
|
||||||
|
|
||||||
|
let body = json!({
|
||||||
|
"searchableAttributes": [
|
||||||
|
"uid",
|
||||||
|
"movie_id",
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"poster",
|
||||||
|
"release_date",
|
||||||
|
"rank",
|
||||||
|
],
|
||||||
|
"displayedAttributes": [
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"poster",
|
||||||
|
"release_date",
|
||||||
|
"rank",
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
server.update_all_settings(body.clone());
|
||||||
|
|
||||||
|
// 2 - Send the settings
|
||||||
|
|
||||||
|
let body = json!({
|
||||||
|
"rankingRules": [
|
||||||
|
"typo",
|
||||||
|
"words",
|
||||||
|
"proximity",
|
||||||
|
"attribute",
|
||||||
|
"wordsPosition",
|
||||||
|
"exactness",
|
||||||
|
"desc(release_date)",
|
||||||
|
"desc(rank)",
|
||||||
|
],
|
||||||
|
"distinctAttribute": "movie_id",
|
||||||
|
"stopWords": [
|
||||||
|
"the",
|
||||||
|
"a",
|
||||||
|
"an",
|
||||||
|
],
|
||||||
|
"synonyms": {
|
||||||
|
"wolverine": ["xmen", "logan"],
|
||||||
|
"logan": ["wolverine"],
|
||||||
|
},
|
||||||
|
"acceptNewFields": false,
|
||||||
|
});
|
||||||
|
|
||||||
|
server.update_all_settings(body.clone());
|
||||||
|
|
||||||
|
// 2 - Send the settings
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"rankingRules": [
|
||||||
|
"typo",
|
||||||
|
"words",
|
||||||
|
"proximity",
|
||||||
|
"attribute",
|
||||||
|
"wordsPosition",
|
||||||
|
"exactness",
|
||||||
|
"desc(release_date)",
|
||||||
|
"desc(rank)",
|
||||||
|
],
|
||||||
|
"distinctAttribute": "movie_id",
|
||||||
|
"searchableAttributes": [
|
||||||
|
"uid",
|
||||||
|
"movie_id",
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"poster",
|
||||||
|
"release_date",
|
||||||
|
"rank",
|
||||||
|
],
|
||||||
|
"displayedAttributes": [
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"poster",
|
||||||
|
"release_date",
|
||||||
|
"rank",
|
||||||
|
],
|
||||||
|
"stopWords": [
|
||||||
|
"the",
|
||||||
|
"a",
|
||||||
|
"an",
|
||||||
|
],
|
||||||
|
"synonyms": {
|
||||||
|
"wolverine": ["xmen", "logan"],
|
||||||
|
"logan": ["wolverine"],
|
||||||
|
},
|
||||||
|
"acceptNewFields": false,
|
||||||
|
});
|
||||||
|
|
||||||
|
let (response, _status_code) = server.get_all_settings();
|
||||||
|
|
||||||
|
assert_json_eq!(expected, response, ordered: false);
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user