mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
add setting endpoint
This commit is contained in:
parent
b08f6737ac
commit
85833e3a0a
@ -72,6 +72,23 @@ async fn main() -> Result<(), MainError> {
|
|||||||
.service(routes::document::update_documents)
|
.service(routes::document::update_documents)
|
||||||
.service(routes::document::delete_documents)
|
.service(routes::document::delete_documents)
|
||||||
.service(routes::document::clear_all_documents)
|
.service(routes::document::clear_all_documents)
|
||||||
|
.service(routes::setting::update_all)
|
||||||
|
.service(routes::setting::get_all)
|
||||||
|
.service(routes::setting::delete_all)
|
||||||
|
.service(routes::setting::get_rules)
|
||||||
|
.service(routes::setting::update_rules)
|
||||||
|
.service(routes::setting::delete_rules)
|
||||||
|
.service(routes::setting::get_distinct)
|
||||||
|
.service(routes::setting::update_distinct)
|
||||||
|
.service(routes::setting::delete_distinct)
|
||||||
|
.service(routes::setting::get_searchable)
|
||||||
|
.service(routes::setting::update_searchable)
|
||||||
|
.service(routes::setting::delete_searchable)
|
||||||
|
.service(routes::setting::get_displayed)
|
||||||
|
.service(routes::setting::update_displayed)
|
||||||
|
.service(routes::setting::delete_displayed)
|
||||||
|
.service(routes::setting::get_accept_new_fields)
|
||||||
|
.service(routes::setting::update_accept_new_fields)
|
||||||
.service(routes::key::list)
|
.service(routes::key::list)
|
||||||
.service(routes::stats::index_stats)
|
.service(routes::stats::index_stats)
|
||||||
.service(routes::stats::get_stats)
|
.service(routes::stats::get_stats)
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState, DEFAULT_RANKING_RULES};
|
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState, DEFAULT_RANKING_RULES};
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||||
use actix_web::{web, get, post, put, delete, HttpResponse};
|
use actix_web::{web, get, post, delete, HttpResponse};
|
||||||
use actix_web as aweb;
|
use actix_web as aweb;
|
||||||
|
|
||||||
use crate::error::{ResponseError};
|
use crate::error::{ResponseError};
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
use crate::routes::{IndexUpdateResponse, IndexParam};
|
use crate::routes::{IndexUpdateResponse, IndexParam};
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/settings")]
|
#[post("/indexes/{index_uid}/settings")]
|
||||||
pub async fn get_all(
|
pub async fn update_all(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
@ -86,303 +86,371 @@ pub async fn get_all(
|
|||||||
Ok(HttpResponse::Ok().json(settings))
|
Ok(HttpResponse::Ok().json(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
|
#[get("/indexes/{index_uid}/settings")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn get_all(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let settings: Settings =
|
path: web::Path<IndexParam>,
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
body: web::Json<Settings>,
|
||||||
// let db = &ctx.state().db;
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
let mut writer = data.db.update_write_txn()
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
let settings = body.into_inner().into_update()
|
||||||
// writer.commit()?;
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
#[delete("/indexes/{index_uid}/settings")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn delete_all(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
// let mut writer = db.update_write_txn()?;
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let mut writer = data.db.update_write_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let settings = SettingsUpdate {
|
let settings = SettingsUpdate {
|
||||||
// ranking_rules: UpdateState::Clear,
|
ranking_rules: UpdateState::Clear,
|
||||||
// distinct_attribute: UpdateState::Clear,
|
distinct_attribute: UpdateState::Clear,
|
||||||
// primary_key: UpdateState::Clear,
|
primary_key: UpdateState::Clear,
|
||||||
// searchable_attributes: UpdateState::Clear,
|
searchable_attributes: UpdateState::Clear,
|
||||||
// displayed_attributes: UpdateState::Clear,
|
displayed_attributes: UpdateState::Clear,
|
||||||
// stop_words: UpdateState::Clear,
|
stop_words: UpdateState::Clear,
|
||||||
// synonyms: UpdateState::Clear,
|
synonyms: UpdateState::Clear,
|
||||||
// accept_new_fields: UpdateState::Clear,
|
accept_new_fields: UpdateState::Clear,
|
||||||
// };
|
};
|
||||||
|
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// writer.commit()?;
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
|
}
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
#[get("/indexes/{index_uid}/settings/ranking-rules")]
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
pub async fn get_rules(
|
||||||
// }
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let reader = data.db.main_read_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
|
let ranking_rules = index
|
||||||
// ctx.is_allowed(Private)?;
|
.main
|
||||||
// let index = ctx.index()?;
|
.ranking_rules(&reader)
|
||||||
// let db = &ctx.state().db;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||||
// let reader = db.main_read_txn()?;
|
.unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| r.to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
// let ranking_rules = index
|
Ok(HttpResponse::Ok().json(ranking_rules))
|
||||||
// .main
|
}
|
||||||
// .ranking_rules(&reader)?
|
|
||||||
// .unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
|
||||||
// .into_iter()
|
|
||||||
// .map(|r| r.to_string())
|
|
||||||
// .collect::<Vec<String>>();
|
|
||||||
|
|
||||||
// Ok(tide::Response::new(200).body_json(&ranking_rules).unwrap())
|
#[post("/indexes/{index_uid}/settings/ranking-rules")]
|
||||||
// }
|
pub async fn update_rules(
|
||||||
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
body: web::Json<Option<Vec<String>>>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
let settings = Settings {
|
||||||
// ctx.is_allowed(Private)?;
|
ranking_rules: Some(body.into_inner()),
|
||||||
// let index = ctx.index()?;
|
..Settings::default()
|
||||||
// let ranking_rules: Option<Vec<String>> =
|
};
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
|
||||||
// let db = &ctx.state().db;
|
|
||||||
|
|
||||||
// let settings = Settings {
|
let mut writer = data.db.update_write_txn()
|
||||||
// ranking_rules: Some(ranking_rules),
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// ..Settings::default()
|
let settings = settings.into_update()
|
||||||
// };
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
}
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
|
||||||
// writer.commit()?;
|
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
#[delete("/indexes/{index_uid}/settings/ranking-rules")]
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
pub async fn delete_rules(
|
||||||
// }
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let mut writer = data.db.update_write_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
let settings = SettingsUpdate {
|
||||||
// ctx.is_allowed(Private)?;
|
ranking_rules: UpdateState::Clear,
|
||||||
// let index = ctx.index()?;
|
..SettingsUpdate::default()
|
||||||
// let db = &ctx.state().db;
|
};
|
||||||
// let mut writer = db.update_write_txn()?;
|
|
||||||
|
|
||||||
// let settings = SettingsUpdate {
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// ranking_rules: UpdateState::Clear,
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// ..SettingsUpdate::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// writer.commit()?;
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
|
}
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
#[get("/indexes/{index_uid}/settings/distinct-attribute")]
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
pub async fn get_distinct(
|
||||||
// }
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let reader = data.db.main_read_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let distinct_attribute = index.main.distinct_attribute(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
Ok(HttpResponse::Ok().json(distinct_attribute))
|
||||||
// ctx.is_allowed(Private)?;
|
}
|
||||||
// let index = ctx.index()?;
|
|
||||||
// let db = &ctx.state().db;
|
|
||||||
// let reader = db.main_read_txn()?;
|
|
||||||
|
|
||||||
// let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
#[post("/indexes/{index_uid}/settings/distinct-attribute")]
|
||||||
|
pub async fn update_distinct(
|
||||||
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
body: web::Json<Option<String>>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// Ok(tide::Response::new(200)
|
let settings = Settings {
|
||||||
// .body_json(&distinct_attribute)
|
distinct_attribute: Some(body.into_inner()),
|
||||||
// .unwrap())
|
..Settings::default()
|
||||||
// }
|
};
|
||||||
|
|
||||||
// pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
let mut writer = data.db.update_write_txn()
|
||||||
// ctx.is_allowed(Private)?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// let index = ctx.index()?;
|
let settings = settings.into_update()
|
||||||
// let distinct_attribute: Option<String> =
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// let db = &ctx.state().db;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let settings = Settings {
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// distinct_attribute: Some(distinct_attribute),
|
}
|
||||||
// ..Settings::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
#[delete("/indexes/{index_uid}/settings/distinct-attribute")]
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
pub async fn delete_distinct(
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
data: web::Data<Data>,
|
||||||
// writer.commit()?;
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let mut writer = data.db.update_write_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
let settings = SettingsUpdate {
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
distinct_attribute: UpdateState::Clear,
|
||||||
// }
|
..SettingsUpdate::default()
|
||||||
|
};
|
||||||
|
|
||||||
// pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// ctx.is_allowed(Private)?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// let index = ctx.index()?;
|
|
||||||
// let db = &ctx.state().db;
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
|
||||||
|
|
||||||
// let settings = SettingsUpdate {
|
writer.commit()
|
||||||
// distinct_attribute: UpdateState::Clear,
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// ..SettingsUpdate::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
|
}
|
||||||
|
|
||||||
// writer.commit()?;
|
#[get("/indexes/{index_uid}/settings/searchable-attributes")]
|
||||||
|
pub async fn get_searchable(
|
||||||
|
data: web::Data<Data>,
|
||||||
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let reader = data.db.main_read_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let schema = index.main.schema(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let searchable_attributes: Option<Vec<String>> =
|
||||||
|
schema.map(|s| s.indexed_name().iter().map(|i| (*i).to_string()).collect());
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Ok().json(searchable_attributes))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
#[post("/indexes/{index_uid}/settings/searchable-attributes")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn update_searchable(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
// let reader = db.main_read_txn()?;
|
body: web::Json<Option<Vec<String>>>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let schema = index.main.schema(&reader)?;
|
let settings = Settings {
|
||||||
|
searchable_attributes: Some(body.into_inner()),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
|
||||||
// let searchable_attributes: Option<Vec<String>> =
|
let mut writer = data.db.update_write_txn()
|
||||||
// schema.map(|s| s.indexed_name().iter().map(|i| (*i).to_string()).collect());
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let settings = settings.into_update()
|
||||||
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// Ok(tide::Response::new(200)
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// .body_json(&searchable_attributes)
|
}
|
||||||
// .unwrap())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
#[delete("/indexes/{index_uid}/settings/searchable-attributes")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn delete_searchable(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let searchable_attributes: Option<Vec<String>> =
|
path: web::Path<IndexParam>,
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
) -> aweb::Result<HttpResponse> {
|
||||||
// let db = &ctx.state().db;
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let settings = Settings {
|
let settings = SettingsUpdate {
|
||||||
// searchable_attributes: Some(searchable_attributes),
|
searchable_attributes: UpdateState::Clear,
|
||||||
// ..Settings::default()
|
..SettingsUpdate::default()
|
||||||
// };
|
};
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
let mut writer = data.db.update_write_txn()
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// writer.commit()?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
#[get("/indexes/{index_uid}/settings/displayed-attributes")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn get_displayed(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let reader = data.db.main_read_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let settings = SettingsUpdate {
|
let schema = index.main.schema(&reader)
|
||||||
// searchable_attributes: UpdateState::Clear,
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// ..SettingsUpdate::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
let displayed_attributes: Option<HashSet<String>> = schema.map(|s| {
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
s.displayed_name()
|
||||||
// writer.commit()?;
|
.iter()
|
||||||
|
.map(|i| (*i).to_string())
|
||||||
|
.collect()
|
||||||
|
});
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Ok().json(displayed_attributes))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
|
#[post("/indexes/{index_uid}/settings/displayed-attributes")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn update_displayed(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
// let reader = db.main_read_txn()?;
|
body: web::Json<Option<HashSet<String>>>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let schema = index.main.schema(&reader)?;
|
let settings = Settings {
|
||||||
|
displayed_attributes: Some(body.into_inner()),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
|
||||||
// let displayed_attributes: Option<HashSet<String>> = schema.map(|s| {
|
let mut writer = data.db.update_write_txn()
|
||||||
// s.displayed_name()
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// .iter()
|
let settings = settings.into_update()
|
||||||
// .map(|i| (*i).to_string())
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
// .collect()
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// });
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// Ok(tide::Response::new(200)
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// .body_json(&displayed_attributes)
|
}
|
||||||
// .unwrap())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
#[delete("/indexes/{index_uid}/settings/displayed-attributes")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn delete_displayed(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let displayed_attributes: Option<HashSet<String>> =
|
path: web::Path<IndexParam>,
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
) -> aweb::Result<HttpResponse> {
|
||||||
// let db = &ctx.state().db;
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let settings = Settings {
|
let settings = SettingsUpdate {
|
||||||
// displayed_attributes: Some(displayed_attributes),
|
displayed_attributes: UpdateState::Clear,
|
||||||
// ..Settings::default()
|
..SettingsUpdate::default()
|
||||||
// };
|
};
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
let mut writer = data.db.update_write_txn()
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
// writer.commit()?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
#[get("/indexes/{index_uid}/settings/accept-new-fields")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn get_accept_new_fields(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
let reader = data.db.main_read_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// let settings = SettingsUpdate {
|
let schema = index.main.schema(&reader)
|
||||||
// displayed_attributes: UpdateState::Clear,
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
// ..SettingsUpdate::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
let accept_new_fields = schema.map(|s| s.accept_new_fields());
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
|
||||||
// writer.commit()?;
|
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
Ok(HttpResponse::Ok().json(accept_new_fields))
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn get_accept_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
#[post("/indexes/{index_uid}/settings/accept-new-fields")]
|
||||||
// ctx.is_allowed(Private)?;
|
pub async fn update_accept_new_fields(
|
||||||
// let index = ctx.index()?;
|
data: web::Data<Data>,
|
||||||
// let db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
// let reader = db.main_read_txn()?;
|
body: web::Json<Option<bool>>,
|
||||||
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
// let schema = index.main.schema(&reader)?;
|
let settings = Settings {
|
||||||
|
accept_new_fields: Some(body.into_inner()),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
|
||||||
// let accept_new_fields = schema.map(|s| s.accept_new_fields());
|
let mut writer = data.db.update_write_txn()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let settings = settings.into_update()
|
||||||
|
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
|
||||||
|
let update_id = index.settings_update(&mut writer, settings)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
writer.commit()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
// Ok(tide::Response::new(200)
|
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||||
// .body_json(&accept_new_fields)
|
}
|
||||||
// .unwrap())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub async fn update_accept_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
|
|
||||||
// ctx.is_allowed(Private)?;
|
|
||||||
// let index = ctx.index()?;
|
|
||||||
// let accept_new_fields: Option<bool> =
|
|
||||||
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
|
||||||
// let db = &ctx.state().db;
|
|
||||||
|
|
||||||
// let settings = Settings {
|
|
||||||
// accept_new_fields: Some(accept_new_fields),
|
|
||||||
// ..Settings::default()
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut writer = db.update_write_txn()?;
|
|
||||||
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
|
||||||
// let update_id = index.settings_update(&mut writer, settings)?;
|
|
||||||
// writer.commit()?;
|
|
||||||
|
|
||||||
// let response_body = IndexUpdateResponse { update_id };
|
|
||||||
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
|
||||||
// }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user