2020-01-23 11:30:18 +01:00
|
|
|
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState};
|
2020-01-31 10:50:28 +01:00
|
|
|
use serde::Deserialize;
|
2020-01-23 11:30:18 +01:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
2020-01-15 17:10:33 +01:00
|
|
|
use tide::{Request, Response};
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
use crate::error::{ResponseError, SResult};
|
2020-01-15 17:10:33 +01:00
|
|
|
use crate::helpers::tide::RequestExt;
|
2019-10-31 15:00:36 +01:00
|
|
|
use crate::models::token::ACL::*;
|
|
|
|
use crate::routes::document::IndexUpdateResponse;
|
|
|
|
use crate::Data;
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
pub async fn get_all(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 stop_words_fst = index.main.stop_words_fst(&reader)?;
|
|
|
|
let stop_words = stop_words_fst.unwrap_or_default().stream().into_strs()?;
|
|
|
|
let stop_words: BTreeSet<String> = stop_words.into_iter().collect();
|
2020-01-29 18:30:21 +01:00
|
|
|
let stop_words = if stop_words.is_empty() {
|
2020-01-16 19:19:44 +01:00
|
|
|
Some(stop_words)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let synonyms_fst = index.main.synonyms_fst(&reader)?.unwrap_or_default();
|
|
|
|
let synonyms_list = synonyms_fst.stream().into_strs()?;
|
|
|
|
|
|
|
|
let mut synonyms = BTreeMap::new();
|
|
|
|
|
|
|
|
let index_synonyms = &index.synonyms;
|
|
|
|
|
|
|
|
for synonym in synonyms_list {
|
|
|
|
let alternative_list = index_synonyms.synonyms(&reader, synonym.as_bytes())?;
|
|
|
|
|
|
|
|
if let Some(list) = alternative_list {
|
|
|
|
let list = list.stream().into_strs()?;
|
|
|
|
synonyms.insert(synonym, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let synonyms = if synonyms.is_empty() {
|
2020-01-16 19:19:44 +01:00
|
|
|
Some(synonyms)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let ranking_rules = match index.main.ranking_rules(&reader)? {
|
2020-01-23 11:30:18 +01:00
|
|
|
Some(rules) => Some(rules.iter().map(|r| r.to_string()).collect()),
|
2020-01-16 19:19:44 +01:00
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
let ranking_distinct = index.main.ranking_distinct(&reader)?;
|
|
|
|
|
|
|
|
let schema = index.main.schema(&reader)?;
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let identifier = schema.clone().map(|s| s.identifier().to_owned());
|
|
|
|
let searchable_attributes = schema
|
|
|
|
.clone()
|
2020-01-31 10:50:28 +01:00
|
|
|
.map(|s| s.indexed_name().iter().map(|s| (*s).to_string()).collect());
|
2020-01-29 18:30:21 +01:00
|
|
|
let displayed_attributes = schema
|
|
|
|
.clone()
|
2020-01-31 10:50:28 +01:00
|
|
|
.map(|s| s.displayed_name().iter().map(|s| (*s).to_string()).collect());
|
2020-01-29 18:30:21 +01:00
|
|
|
let index_new_fields = schema.map(|s| s.index_new_fields());
|
2020-01-16 19:19:44 +01:00
|
|
|
|
|
|
|
let settings = Settings {
|
2020-01-28 17:45:29 +01:00
|
|
|
ranking_rules: Some(ranking_rules),
|
|
|
|
ranking_distinct: Some(ranking_distinct),
|
2020-01-29 18:30:21 +01:00
|
|
|
identifier: Some(identifier),
|
|
|
|
searchable_attributes: Some(searchable_attributes),
|
|
|
|
displayed_attributes: Some(displayed_attributes),
|
2020-01-28 17:45:29 +01:00
|
|
|
stop_words: Some(stop_words),
|
|
|
|
synonyms: Some(synonyms),
|
|
|
|
index_new_fields: Some(index_new_fields),
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
2019-10-31 15:00:36 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:45:29 +01:00
|
|
|
#[derive(Default, Clone, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
|
|
pub struct UpdateSettings {
|
|
|
|
pub ranking_rules: Option<Vec<String>>,
|
|
|
|
pub ranking_distinct: Option<String>,
|
2020-01-29 18:30:21 +01:00
|
|
|
pub identifier: Option<String>,
|
|
|
|
pub searchable_attributes: Option<Vec<String>>,
|
|
|
|
pub displayed_attributes: Option<HashSet<String>>,
|
2020-01-28 17:45:29 +01:00
|
|
|
pub stop_words: Option<BTreeSet<String>>,
|
|
|
|
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
|
|
|
|
pub index_new_fields: Option<bool>,
|
|
|
|
}
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-28 17:46:51 +01:00
|
|
|
let settings_update: UpdateSettings =
|
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
2020-01-28 17:45:29 +01:00
|
|
|
let settings = Settings {
|
|
|
|
ranking_rules: Some(settings_update.ranking_rules),
|
|
|
|
ranking_distinct: Some(settings_update.ranking_distinct),
|
2020-01-29 18:30:21 +01:00
|
|
|
identifier: Some(settings_update.identifier),
|
|
|
|
searchable_attributes: Some(settings_update.searchable_attributes),
|
|
|
|
displayed_attributes: Some(settings_update.displayed_attributes),
|
2020-01-28 17:45:29 +01:00
|
|
|
stop_words: Some(settings_update.stop_words),
|
|
|
|
synonyms: Some(settings_update.synonyms),
|
|
|
|
index_new_fields: Some(settings_update.index_new_fields),
|
|
|
|
};
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2019-10-31 15:00:36 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
let mut writer = db.update_write_txn()?;
|
|
|
|
|
|
|
|
let settings = SettingsUpdate {
|
|
|
|
ranking_rules: UpdateState::Clear,
|
|
|
|
ranking_distinct: UpdateState::Clear,
|
2020-01-29 18:30:21 +01:00
|
|
|
identifier: UpdateState::Clear,
|
|
|
|
searchable_attributes: UpdateState::Clear,
|
|
|
|
displayed_attributes: UpdateState::Clear,
|
2020-01-16 19:19:44 +01:00
|
|
|
stop_words: UpdateState::Clear,
|
|
|
|
synonyms: UpdateState::Clear,
|
2020-01-27 18:27:42 +01:00
|
|
|
index_new_fields: UpdateState::Clear,
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let update_id = index.settings_update(&mut writer, settings)?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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()?;
|
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
let ranking_rules: Option<Vec<String>> = match index.main.ranking_rules(&reader)? {
|
2020-01-23 11:30:18 +01:00
|
|
|
Some(rules) => Some(rules.iter().map(|r| r.to_string()).collect()),
|
2020-01-16 19:19:44 +01:00
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
Ok(tide::Response::new(200).body_json(&ranking_rules).unwrap())
|
2020-01-20 09:52:24 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-28 16:27:21 +01:00
|
|
|
let ranking_rules: Option<Vec<String>> =
|
2020-01-23 11:30:18 +01:00
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
2020-01-21 12:03:48 +01:00
|
|
|
let settings = Settings {
|
2020-01-28 17:45:29 +01:00
|
|
|
ranking_rules: Some(ranking_rules),
|
2020-01-23 11:30:18 +01:00
|
|
|
..Settings::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
let mut writer = db.update_write_txn()?;
|
|
|
|
|
|
|
|
let settings = SettingsUpdate {
|
|
|
|
ranking_rules: UpdateState::Clear,
|
2020-01-23 11:30:18 +01:00
|
|
|
..SettingsUpdate::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let update_id = index.settings_update(&mut writer, settings)?;
|
|
|
|
|
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsRead)?;
|
|
|
|
let index = ctx.index()?;
|
2019-11-26 16:12:06 +01:00
|
|
|
let db = &ctx.state().db;
|
2020-01-16 16:58:57 +01:00
|
|
|
let reader = db.main_read_txn()?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let ranking_distinct = index.main.ranking_distinct(&reader)?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
Ok(tide::Response::new(200)
|
|
|
|
.body_json(&ranking_distinct)
|
|
|
|
.unwrap())
|
2019-10-31 15:00:36 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-28 16:27:21 +01:00
|
|
|
let ranking_distinct: Option<String> =
|
2020-01-23 11:30:18 +01:00
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
2020-01-21 12:03:48 +01:00
|
|
|
let settings = Settings {
|
2020-01-28 17:45:29 +01:00
|
|
|
ranking_distinct: Some(ranking_distinct),
|
2020-01-23 11:30:18 +01:00
|
|
|
..Settings::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
let mut writer = db.update_write_txn()?;
|
|
|
|
|
|
|
|
let settings = SettingsUpdate {
|
|
|
|
ranking_distinct: UpdateState::Clear,
|
2020-01-23 11:30:18 +01:00
|
|
|
..SettingsUpdate::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let update_id = index.settings_update(&mut writer, settings)?;
|
|
|
|
|
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsRead)?;
|
|
|
|
let index = ctx.index()?;
|
2019-11-26 16:12:06 +01:00
|
|
|
let db = &ctx.state().db;
|
2020-01-16 16:58:57 +01:00
|
|
|
let reader = db.main_read_txn()?;
|
2020-01-16 19:19:44 +01:00
|
|
|
|
|
|
|
let schema = index.main.schema(&reader)?;
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let identifier = schema.map(|s| s.identifier().to_string());
|
2020-01-16 19:19:44 +01:00
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(200).body_json(&identifier).unwrap())
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_searchable(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 schema = index.main.schema(&reader)?;
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let searchable_attributes: Option<HashSet<String>> =
|
2020-01-31 10:50:28 +01:00
|
|
|
schema.map(|s| s.indexed_name().iter().map(|i| (*i).to_string()).collect());
|
2020-01-16 19:19:44 +01:00
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
Ok(tide::Response::new(200)
|
2020-01-29 18:30:21 +01:00
|
|
|
.body_json(&searchable_attributes)
|
2020-01-28 16:27:21 +01:00
|
|
|
.unwrap())
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let searchable_attributes: Option<Vec<String>> =
|
2020-01-23 11:30:18 +01:00
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
2020-01-21 12:03:48 +01:00
|
|
|
let settings = Settings {
|
2020-01-29 18:30:21 +01:00
|
|
|
searchable_attributes: Some(searchable_attributes),
|
2020-01-23 11:30:18 +01:00
|
|
|
..Settings::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
2020-01-16 16:58:57 +01:00
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let settings = SettingsUpdate {
|
2020-01-29 18:30:21 +01:00
|
|
|
searchable_attributes: UpdateState::Clear,
|
2020-01-23 11:30:18 +01:00
|
|
|
..SettingsUpdate::default()
|
2019-10-31 15:00:36 +01:00
|
|
|
};
|
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let mut writer = db.update_write_txn()?;
|
|
|
|
let update_id = index.settings_update(&mut writer, settings)?;
|
|
|
|
writer.commit()?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
|
2020-01-16 19:19:44 +01:00
|
|
|
ctx.is_allowed(SettingsRead)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
let reader = db.main_read_txn()?;
|
|
|
|
|
|
|
|
let schema = index.main.schema(&reader)?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let displayed_attributes: Option<HashSet<String>> =
|
2020-01-31 10:50:28 +01:00
|
|
|
schema.map(|s| s.displayed_name().iter().map(|i| (*i).to_string()).collect());
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
Ok(tide::Response::new(200)
|
2020-01-29 18:30:21 +01:00
|
|
|
.body_json(&displayed_attributes)
|
2020-01-28 16:27:21 +01:00
|
|
|
.unwrap())
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let displayed_attributes: Option<HashSet<String>> =
|
2020-01-23 11:30:18 +01:00
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
let db = &ctx.state().db;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-16 19:19:44 +01:00
|
|
|
let settings = Settings {
|
2020-01-29 18:30:21 +01:00
|
|
|
displayed_attributes: Some(displayed_attributes),
|
2020-01-23 11:30:18 +01:00
|
|
|
..Settings::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-16 19:19:44 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-16 19:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
|
|
|
let settings = SettingsUpdate {
|
2020-01-29 18:30:21 +01:00
|
|
|
displayed_attributes: UpdateState::Clear,
|
2020-01-23 11:30:18 +01:00
|
|
|
..SettingsUpdate::default()
|
2020-01-16 19:19:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut writer = db.update_write_txn()?;
|
|
|
|
let update_id = index.settings_update(&mut writer, settings)?;
|
2020-01-16 16:58:57 +01:00
|
|
|
writer.commit()?;
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2019-10-31 15:00:36 +01:00
|
|
|
}
|
2020-01-27 18:33:40 +01:00
|
|
|
|
|
|
|
pub async fn get_index_new_fields(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 schema = index.main.schema(&reader)?;
|
|
|
|
|
2020-01-29 18:30:21 +01:00
|
|
|
let index_new_fields = schema.map(|s| s.index_new_fields());
|
2020-01-27 18:33:40 +01:00
|
|
|
|
2020-01-28 16:27:21 +01:00
|
|
|
Ok(tide::Response::new(200)
|
|
|
|
.body_json(&index_new_fields)
|
|
|
|
.unwrap())
|
2020-01-27 18:33:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update_index_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
|
|
|
|
ctx.is_allowed(SettingsWrite)?;
|
|
|
|
let index = ctx.index()?;
|
2020-01-28 16:27:21 +01:00
|
|
|
let index_new_fields: Option<bool> =
|
2020-01-27 18:33:40 +01:00
|
|
|
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
|
|
|
let db = &ctx.state().db;
|
|
|
|
|
|
|
|
let settings = Settings {
|
2020-01-28 17:45:29 +01:00
|
|
|
index_new_fields: Some(index_new_fields),
|
2020-01-27 18:33:40 +01:00
|
|
|
..Settings::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut writer = db.update_write_txn()?;
|
2020-01-29 18:30:21 +01:00
|
|
|
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
2020-01-27 18:33:40 +01:00
|
|
|
writer.commit()?;
|
|
|
|
|
|
|
|
let response_body = IndexUpdateResponse { update_id };
|
2020-01-29 18:30:21 +01:00
|
|
|
Ok(tide::Response::new(202).body_json(&response_body)?)
|
2020-01-27 18:33:40 +01:00
|
|
|
}
|