mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
fix for review
This commit is contained in:
parent
14b5fc4d6c
commit
a5b0e468ee
48 changed files with 558 additions and 1216 deletions
|
@ -1,424 +0,0 @@
|
|||
//! Cors middleware
|
||||
|
||||
use futures::future::BoxFuture;
|
||||
use http::header::HeaderValue;
|
||||
use http::{header, Method, StatusCode};
|
||||
use http_service::Body;
|
||||
|
||||
use tide::middleware::{Middleware, Next};
|
||||
use tide::{Request, Response};
|
||||
|
||||
/// Middleware for CORS
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// use http::header::HeaderValue;
|
||||
/// use tide::middleware::{Cors, Origin};
|
||||
///
|
||||
/// Cors::new()
|
||||
/// .allow_methods(HeaderValue::from_static("GET, POST, OPTIONS"))
|
||||
/// .allow_origin(Origin::from("*"))
|
||||
/// .allow_credentials(false);
|
||||
/// ```
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
pub struct Cors {
|
||||
allow_credentials: Option<HeaderValue>,
|
||||
allow_headers: HeaderValue,
|
||||
allow_methods: HeaderValue,
|
||||
allow_origin: Origin,
|
||||
expose_headers: Option<HeaderValue>,
|
||||
max_age: HeaderValue,
|
||||
}
|
||||
|
||||
pub const DEFAULT_MAX_AGE: &str = "86400";
|
||||
pub const DEFAULT_METHODS: &str = "GET, POST, OPTIONS";
|
||||
pub const WILDCARD: &str = "*";
|
||||
|
||||
impl Cors {
|
||||
/// Creates a new Cors middleware.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
allow_credentials: None,
|
||||
allow_headers: HeaderValue::from_static(WILDCARD),
|
||||
allow_methods: HeaderValue::from_static(DEFAULT_METHODS),
|
||||
allow_origin: Origin::Any,
|
||||
expose_headers: None,
|
||||
max_age: HeaderValue::from_static(DEFAULT_MAX_AGE),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set allow_credentials and return new Cors
|
||||
pub fn allow_credentials(mut self, allow_credentials: bool) -> Self {
|
||||
self.allow_credentials = match HeaderValue::from_str(&allow_credentials.to_string()) {
|
||||
Ok(header) => Some(header),
|
||||
Err(_) => None,
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
/// Set allow_headers and return new Cors
|
||||
pub fn allow_headers<T: Into<HeaderValue>>(mut self, headers: T) -> Self {
|
||||
self.allow_headers = headers.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set max_age and return new Cors
|
||||
pub fn max_age<T: Into<HeaderValue>>(mut self, max_age: T) -> Self {
|
||||
self.max_age = max_age.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set allow_methods and return new Cors
|
||||
pub fn allow_methods<T: Into<HeaderValue>>(mut self, methods: T) -> Self {
|
||||
self.allow_methods = methods.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set allow_origin and return new Cors
|
||||
pub fn allow_origin<T: Into<Origin>>(mut self, origin: T) -> Self {
|
||||
self.allow_origin = origin.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set expose_headers and return new Cors
|
||||
pub fn expose_headers<T: Into<HeaderValue>>(mut self, headers: T) -> Self {
|
||||
self.expose_headers = Some(headers.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn build_preflight_response(&self, origin: &HeaderValue) -> http::response::Response<Body> {
|
||||
let mut response = http::Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header::<_, HeaderValue>(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin.clone())
|
||||
.header(
|
||||
header::ACCESS_CONTROL_ALLOW_METHODS,
|
||||
self.allow_methods.clone(),
|
||||
)
|
||||
.header(
|
||||
header::ACCESS_CONTROL_ALLOW_HEADERS,
|
||||
self.allow_headers.clone(),
|
||||
)
|
||||
.header(header::ACCESS_CONTROL_MAX_AGE, self.max_age.clone())
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
|
||||
if let Some(allow_credentials) = self.allow_credentials.clone() {
|
||||
response
|
||||
.headers_mut()
|
||||
.append(header::ACCESS_CONTROL_ALLOW_CREDENTIALS, allow_credentials);
|
||||
}
|
||||
|
||||
if let Some(expose_headers) = self.expose_headers.clone() {
|
||||
response
|
||||
.headers_mut()
|
||||
.append(header::ACCESS_CONTROL_EXPOSE_HEADERS, expose_headers);
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
/// Look at origin of request and determine allow_origin
|
||||
fn response_origin<T: Into<HeaderValue>>(&self, origin: T) -> Option<HeaderValue> {
|
||||
let origin = origin.into();
|
||||
if !self.is_valid_origin(origin.clone()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
match self.allow_origin {
|
||||
Origin::Any => Some(HeaderValue::from_static(WILDCARD)),
|
||||
_ => Some(origin),
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine if origin is appropriate
|
||||
fn is_valid_origin<T: Into<HeaderValue>>(&self, origin: T) -> bool {
|
||||
let origin = match origin.into().to_str() {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(_) => return false,
|
||||
};
|
||||
|
||||
match &self.allow_origin {
|
||||
Origin::Any => true,
|
||||
Origin::Exact(s) => s == &origin,
|
||||
Origin::List(list) => list.contains(&origin),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<State: Send + Sync + 'static> Middleware<State> for Cors {
|
||||
fn handle<'a>(&'a self, req: Request<State>, next: Next<'a, State>) -> BoxFuture<'a, Response> {
|
||||
Box::pin(async move {
|
||||
let origin = req
|
||||
.headers()
|
||||
.get(header::ORIGIN)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| HeaderValue::from_static(""));
|
||||
|
||||
if !self.is_valid_origin(&origin) {
|
||||
return http::Response::builder()
|
||||
.status(StatusCode::UNAUTHORIZED)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
.into();
|
||||
}
|
||||
|
||||
// Return results immediately upon preflight request
|
||||
if req.method() == Method::OPTIONS {
|
||||
return self.build_preflight_response(&origin).into();
|
||||
}
|
||||
|
||||
let mut response: http_service::Response = next.run(req).await.into();
|
||||
let headers = response.headers_mut();
|
||||
|
||||
headers.append(
|
||||
header::ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||
self.response_origin(origin).unwrap(),
|
||||
);
|
||||
|
||||
if let Some(allow_credentials) = self.allow_credentials.clone() {
|
||||
headers.append(header::ACCESS_CONTROL_ALLOW_CREDENTIALS, allow_credentials);
|
||||
}
|
||||
|
||||
if let Some(expose_headers) = self.expose_headers.clone() {
|
||||
headers.append(header::ACCESS_CONTROL_EXPOSE_HEADERS, expose_headers);
|
||||
}
|
||||
response.into()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Cors {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// allow_origin enum
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub enum Origin {
|
||||
/// Wildcard. Accept all origin requests
|
||||
Any,
|
||||
/// Set a single allow_origin target
|
||||
Exact(String),
|
||||
/// Set multiple allow_origin targets
|
||||
List(Vec<String>),
|
||||
}
|
||||
|
||||
impl From<String> for Origin {
|
||||
fn from(s: String) -> Self {
|
||||
if s == "*" {
|
||||
return Origin::Any;
|
||||
}
|
||||
Origin::Exact(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Origin {
|
||||
fn from(s: &str) -> Self {
|
||||
Origin::from(s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<String>> for Origin {
|
||||
fn from(list: Vec<String>) -> Self {
|
||||
if list.len() == 1 {
|
||||
return Self::from(list[0].clone());
|
||||
}
|
||||
|
||||
Origin::List(list)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<&str>> for Origin {
|
||||
fn from(list: Vec<&str>) -> Self {
|
||||
Origin::from(list.iter().map(|s| s.to_string()).collect::<Vec<String>>())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use http::header::HeaderValue;
|
||||
use http_service::Body;
|
||||
use http_service_mock::make_server;
|
||||
|
||||
const ALLOW_ORIGIN: &str = "example.com";
|
||||
const ALLOW_METHODS: &str = "GET, POST, OPTIONS, DELETE";
|
||||
const EXPOSE_HEADER: &str = "X-My-Custom-Header";
|
||||
|
||||
const ENDPOINT: &str = "/cors";
|
||||
|
||||
fn app() -> tide::Server<()> {
|
||||
let mut app = tide::Server::new();
|
||||
app.at(ENDPOINT).get(|_| async move { "Hello World" });
|
||||
|
||||
app
|
||||
}
|
||||
|
||||
fn request() -> http::Request<http_service::Body> {
|
||||
http::Request::get(ENDPOINT)
|
||||
.header(http::header::ORIGIN, ALLOW_ORIGIN)
|
||||
.method(http::method::Method::GET)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preflight_request() {
|
||||
let mut app = app();
|
||||
app.middleware(
|
||||
Cors::new()
|
||||
.allow_origin(Origin::from(ALLOW_ORIGIN))
|
||||
.allow_methods(HeaderValue::from_static(ALLOW_METHODS))
|
||||
.expose_headers(HeaderValue::from_static(EXPOSE_HEADER))
|
||||
.allow_credentials(true),
|
||||
);
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
|
||||
let req = http::Request::get(ENDPOINT)
|
||||
.header(http::header::ORIGIN, ALLOW_ORIGIN)
|
||||
.method(http::method::Method::OPTIONS)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-origin").unwrap(),
|
||||
ALLOW_ORIGIN
|
||||
);
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-methods").unwrap(),
|
||||
ALLOW_METHODS
|
||||
);
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-headers").unwrap(),
|
||||
WILDCARD
|
||||
);
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-max-age").unwrap(),
|
||||
DEFAULT_MAX_AGE
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
res.headers()
|
||||
.get("access-control-allow-credentials")
|
||||
.unwrap(),
|
||||
"true"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn default_cors_middleware() {
|
||||
let mut app = app();
|
||||
app.middleware(Cors::new());
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
let res = server.simulate(request()).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-origin").unwrap(),
|
||||
"*"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_cors_middleware() {
|
||||
let mut app = app();
|
||||
app.middleware(
|
||||
Cors::new()
|
||||
.allow_origin(Origin::from(ALLOW_ORIGIN))
|
||||
.allow_credentials(false)
|
||||
.allow_methods(HeaderValue::from_static(ALLOW_METHODS))
|
||||
.expose_headers(HeaderValue::from_static(EXPOSE_HEADER)),
|
||||
);
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
let res = server.simulate(request()).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-origin").unwrap(),
|
||||
ALLOW_ORIGIN
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn credentials_true() {
|
||||
let mut app = app();
|
||||
app.middleware(Cors::new().allow_credentials(true));
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
let res = server.simulate(request()).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
assert_eq!(
|
||||
res.headers()
|
||||
.get("access-control-allow-credentials")
|
||||
.unwrap(),
|
||||
"true"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_allow_origin_list() {
|
||||
let mut app = app();
|
||||
let origins = vec![ALLOW_ORIGIN, "foo.com", "bar.com"];
|
||||
app.middleware(Cors::new().allow_origin(origins.clone()));
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
|
||||
for origin in origins {
|
||||
let request = http::Request::get(ENDPOINT)
|
||||
.header(http::header::ORIGIN, origin)
|
||||
.method(http::method::Method::GET)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
|
||||
let res = server.simulate(request).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
assert_eq!(
|
||||
res.headers().get("access-control-allow-origin").unwrap(),
|
||||
origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_set_origin_header() {
|
||||
let mut app = app();
|
||||
app.middleware(Cors::new());
|
||||
|
||||
let request = http::Request::get(ENDPOINT)
|
||||
.method(http::method::Method::GET)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
let res = server.simulate(request).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unauthorized_origin() {
|
||||
let mut app = app();
|
||||
app.middleware(Cors::new().allow_origin(ALLOW_ORIGIN));
|
||||
|
||||
let request = http::Request::get(ENDPOINT)
|
||||
.header(http::header::ORIGIN, "unauthorize-origin.net")
|
||||
.method(http::method::Method::GET)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
|
||||
let mut server = make_server(app.into_http_service()).unwrap();
|
||||
let res = server.simulate(request).unwrap();
|
||||
|
||||
assert_eq!(res.status(), 401);
|
||||
}
|
||||
}
|
|
@ -92,7 +92,7 @@ impl DataInner {
|
|||
// convert attributes to their names
|
||||
let frequency: HashMap<_, _> = fields_frequency
|
||||
.into_iter()
|
||||
.map(|(a, c)| (schema.get_name(a).unwrap(), c))
|
||||
.map(|(a, c)| (schema.name(a).unwrap().to_string(), c))
|
||||
.collect();
|
||||
|
||||
index
|
||||
|
|
|
@ -127,6 +127,12 @@ fn error(message: String, status: StatusCode) -> Response {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for ResponseError {
|
||||
fn from(err: serde_json::Error) -> ResponseError {
|
||||
ResponseError::internal(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::Error> for ResponseError {
|
||||
fn from(err: meilisearch_core::Error) -> ResponseError {
|
||||
ResponseError::internal(err)
|
||||
|
@ -151,11 +157,16 @@ impl From<SearchError> for ResponseError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::settings::RankingRuleConversionError> for ResponseError {
|
||||
fn from(err: meilisearch_core::settings::RankingRuleConversionError) -> ResponseError {
|
||||
ResponseError::internal(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntoInternalError<T> {
|
||||
fn into_internal_error(self) -> SResult<T>;
|
||||
}
|
||||
|
||||
/// Must be used only
|
||||
impl<T> IntoInternalError<T> for Option<T> {
|
||||
fn into_internal_error(self) -> SResult<T> {
|
||||
match self {
|
||||
|
|
|
@ -63,6 +63,12 @@ impl From<meilisearch_core::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<heed::Error> for Error {
|
||||
fn from(error: heed::Error) -> Self {
|
||||
Error::Internal(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IndexSearchExt {
|
||||
fn new_search(&self, query: String) -> SearchBuilder;
|
||||
}
|
||||
|
@ -171,7 +177,7 @@ impl<'a> SearchBuilder<'a> {
|
|||
let ref_index = &self.index;
|
||||
let value = value.trim().to_lowercase();
|
||||
|
||||
let attr = match schema.get_id(attr) {
|
||||
let attr = match schema.id(attr) {
|
||||
Some(attr) => attr,
|
||||
None => return Err(Error::UnknownFilteredAttribute),
|
||||
};
|
||||
|
@ -271,7 +277,7 @@ impl<'a> SearchBuilder<'a> {
|
|||
ranked_map: &'a RankedMap,
|
||||
schema: &Schema,
|
||||
) -> Result<Option<Criteria<'a>>, Error> {
|
||||
let ranking_rules = self.index.main.ranking_rules(reader).unwrap();
|
||||
let ranking_rules = self.index.main.ranking_rules(reader)?;
|
||||
|
||||
if let Some(ranking_rules) = ranking_rules {
|
||||
let mut builder = CriteriaBuilder::with_capacity(7 + ranking_rules.len());
|
||||
|
@ -283,10 +289,18 @@ impl<'a> SearchBuilder<'a> {
|
|||
RankingRule::Attribute => builder.push(Attribute),
|
||||
RankingRule::WordsPosition => builder.push(WordsPosition),
|
||||
RankingRule::Exact => builder.push(Exact),
|
||||
RankingRule::Asc(field) => builder
|
||||
.push(SortByAttr::lower_is_better(&ranked_map, &schema, &field).unwrap()),
|
||||
RankingRule::Dsc(field) => builder
|
||||
.push(SortByAttr::higher_is_better(&ranked_map, &schema, &field).unwrap()),
|
||||
RankingRule::Asc(field) => {
|
||||
match SortByAttr::lower_is_better(&ranked_map, &schema, &field) {
|
||||
Ok(rule) => builder.push(rule),
|
||||
Err(err) => error!("Error during criteria builder; {:?}", err),
|
||||
}
|
||||
}
|
||||
RankingRule::Dsc(field) => {
|
||||
match SortByAttr::higher_is_better(&ranked_map, &schema, &field) {
|
||||
Ok(rule) => builder.push(rule),
|
||||
Err(err) => error!("Error during criteria builder; {:?}", err),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
builder.push(DocumentId);
|
||||
|
@ -334,8 +348,6 @@ pub struct SearchResult {
|
|||
pub limit: usize,
|
||||
pub processing_time_ms: usize,
|
||||
pub query: String,
|
||||
// pub parsed_query: String,
|
||||
// pub params: Option<String>,
|
||||
}
|
||||
|
||||
fn crop_text(
|
||||
|
@ -369,7 +381,7 @@ fn crop_document(
|
|||
matches.sort_unstable_by_key(|m| (m.char_index, m.char_length));
|
||||
|
||||
for (field, length) in fields {
|
||||
let attribute = match schema.get_id(field) {
|
||||
let attribute = match schema.id(field) {
|
||||
Some(attribute) => attribute,
|
||||
None => continue,
|
||||
};
|
||||
|
@ -398,16 +410,16 @@ fn calculate_matches(
|
|||
) -> MatchesInfos {
|
||||
let mut matches_result: HashMap<String, Vec<MatchPosition>> = HashMap::new();
|
||||
for m in matches.iter() {
|
||||
if let Some(attribute) = schema.get_name(FieldId::new(m.attribute)) {
|
||||
if let Some(attribute) = schema.name(FieldId::new(m.attribute)) {
|
||||
if let Some(attributes_to_retrieve) = attributes_to_retrieve.clone() {
|
||||
if !attributes_to_retrieve.contains(attribute.as_str()) {
|
||||
if !attributes_to_retrieve.contains(attribute) {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if !schema.get_displayed_name().contains(attribute.as_str()) {
|
||||
if !schema.displayed_name().contains(attribute) {
|
||||
continue;
|
||||
}
|
||||
if let Some(pos) = matches_result.get_mut(&attribute) {
|
||||
if let Some(pos) = matches_result.get_mut(attribute) {
|
||||
pos.push(MatchPosition {
|
||||
start: m.char_index as usize,
|
||||
length: m.char_length as usize,
|
||||
|
@ -418,7 +430,7 @@ fn calculate_matches(
|
|||
start: m.char_index as usize,
|
||||
length: m.char_length as usize,
|
||||
});
|
||||
matches_result.insert(attribute, positions);
|
||||
matches_result.insert(attribute.to_string(), positions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ impl RequestExt for Request<Data> {
|
|||
fn url_param(&self, name: &str) -> SResult<String> {
|
||||
let param = self
|
||||
.param::<String>(name)
|
||||
.map_err(|_| ResponseError::bad_parameter("identifier", ""))?;
|
||||
.map_err(|_| ResponseError::bad_parameter("identifier", name))?;
|
||||
Ok(param)
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ impl RequestExt for Request<Data> {
|
|||
fn identifier(&self) -> SResult<String> {
|
||||
let name = self
|
||||
.param::<String>("identifier")
|
||||
.map_err(|_| ResponseError::bad_parameter("identifier", ""))?;
|
||||
.map_err(|_| ResponseError::bad_parameter("identifier", "identifier"))?;
|
||||
|
||||
Ok(name)
|
||||
}
|
||||
|
|
|
@ -5,17 +5,14 @@ use async_std::task;
|
|||
use log::info;
|
||||
use main_error::MainError;
|
||||
use structopt::StructOpt;
|
||||
use tide::middleware::RequestLogger;
|
||||
use tide::middleware::{Cors, RequestLogger};
|
||||
|
||||
use meilisearch_http::data::Data;
|
||||
use meilisearch_http::option::Opt;
|
||||
use meilisearch_http::routes;
|
||||
use meilisearch_http::routes::index::index_update_callback;
|
||||
|
||||
use cors::Cors;
|
||||
|
||||
mod analytics;
|
||||
mod cors;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[global_allocator]
|
||||
|
@ -40,15 +37,11 @@ pub fn main() -> Result<(), MainError> {
|
|||
|
||||
app.middleware(Cors::new());
|
||||
app.middleware(RequestLogger::new());
|
||||
// app.middleware(tide_compression::Compression::new());
|
||||
// app.middleware(tide_compression::Decompression::new());
|
||||
|
||||
routes::load_routes(&mut app);
|
||||
|
||||
info!("Server HTTP enabled");
|
||||
|
||||
task::block_on(async {
|
||||
app.listen(opt.http_addr).await.unwrap();
|
||||
});
|
||||
task::block_on(app.listen(opt.http_addr))?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ pub async fn get_document(ctx: Request<Data>) -> SResult<Response> {
|
|||
return Err(ResponseError::document_not_found(identifier));
|
||||
}
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&response).unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&response)?)
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize)]
|
||||
|
@ -54,7 +54,7 @@ pub async fn delete_document(ctx: Request<Data>) -> SResult<Response> {
|
|||
update_writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
|
@ -106,7 +106,7 @@ pub async fn get_all_documents(ctx: Request<Data>) -> SResult<Response> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
fn find_identifier(document: &IndexMap<String, Value>) -> Option<String> {
|
||||
|
@ -146,10 +146,10 @@ async fn update_multiple_documents(mut ctx: Request<Data>, is_partial: bool) ->
|
|||
},
|
||||
};
|
||||
let settings = Settings {
|
||||
attribute_identifier: Some(Some(id)),
|
||||
identifier: Some(Some(id)),
|
||||
..Settings::default()
|
||||
};
|
||||
index.settings_update(&mut update_writer, settings.into())?;
|
||||
index.settings_update(&mut update_writer, settings.into_update()?)?;
|
||||
}
|
||||
|
||||
let mut document_addition = if is_partial {
|
||||
|
@ -166,7 +166,7 @@ async fn update_multiple_documents(mut ctx: Request<Data>, is_partial: bool) ->
|
|||
update_writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn add_or_replace_multiple_documents(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -200,7 +200,7 @@ pub async fn delete_multiple_documents(mut ctx: Request<Data>) -> SResult<Respon
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn clear_all_documents(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -215,5 +215,5 @@ pub async fn clear_all_documents(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ pub async fn list_indexes(ctx: Request<Data>) -> SResult<Response> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -87,7 +87,7 @@ pub async fn get_index(ctx: Request<Data>) -> SResult<Response> {
|
|||
updated_at,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -95,7 +95,7 @@ pub async fn get_index(ctx: Request<Data>) -> SResult<Response> {
|
|||
struct IndexCreateRequest {
|
||||
name: Option<String>,
|
||||
uid: Option<String>,
|
||||
attribute_identifier: Option<String>,
|
||||
identifier: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -150,10 +150,10 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
.updated_at(&writer)?
|
||||
.into_internal_error()?;
|
||||
|
||||
if let Some(id) = body.attribute_identifier {
|
||||
if let Some(id) = body.identifier {
|
||||
created_index
|
||||
.main
|
||||
.put_schema(&mut writer, &Schema::with_identifier(id))?;
|
||||
.put_schema(&mut writer, &Schema::with_identifier(&id))?;
|
||||
}
|
||||
|
||||
writer.commit()?;
|
||||
|
@ -165,7 +165,7 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
updated_at,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(201).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(201).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -214,7 +214,7 @@ pub async fn update_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
updated_at,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_update_status(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
|
|
@ -23,175 +23,131 @@ async fn into_response<T: IntoResponse, U: IntoResponse>(
|
|||
}
|
||||
|
||||
pub fn load_routes(app: &mut tide::Server<Data>) {
|
||||
app.at("").nest(|router| {
|
||||
// expose the web interface static files
|
||||
router.at("/").get(|_| {
|
||||
async move {
|
||||
let response = include_str!("../../public/interface.html");
|
||||
response
|
||||
}
|
||||
});
|
||||
router.at("/bulma.min.css").get(|_| {
|
||||
async {
|
||||
let response = include_str!("../../public/bulma.min.css");
|
||||
response
|
||||
}
|
||||
});
|
||||
|
||||
router.at("/indexes").nest(|router| {
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(index::list_indexes(ctx)))
|
||||
.post(|ctx| into_response(index::create_index(ctx)));
|
||||
|
||||
router
|
||||
.at("/search")
|
||||
.post(|ctx| into_response(search::search_multi_index(ctx)));
|
||||
|
||||
router.at("/:index").nest(|router| {
|
||||
router
|
||||
.at("/search")
|
||||
.get(|ctx| into_response(search::search_with_url_query(ctx)));
|
||||
|
||||
router.at("/updates").nest(|router| {
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(index::get_all_updates_status(ctx)));
|
||||
|
||||
router
|
||||
.at("/:update_id")
|
||||
.get(|ctx| into_response(index::get_update_status(ctx)));
|
||||
});
|
||||
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(index::get_index(ctx)))
|
||||
.put(|ctx| into_response(index::update_index(ctx)))
|
||||
.delete(|ctx| into_response(index::delete_index(ctx)));
|
||||
|
||||
router.at("/documents").nest(|router| {
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(document::get_all_documents(ctx)))
|
||||
.post(|ctx| into_response(document::add_or_replace_multiple_documents(ctx)))
|
||||
.put(|ctx| into_response(document::add_or_update_multiple_documents(ctx)))
|
||||
.delete(|ctx| into_response(document::clear_all_documents(ctx)));
|
||||
|
||||
router.at("/:identifier").nest(|router| {
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(document::get_document(ctx)))
|
||||
.delete(|ctx| into_response(document::delete_document(ctx)));
|
||||
});
|
||||
|
||||
router
|
||||
.at("/delete-batch")
|
||||
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
|
||||
});
|
||||
|
||||
router.at("/settings").nest(|router| {
|
||||
router
|
||||
.get(|ctx| into_response(setting::get_all(ctx)))
|
||||
.post(|ctx| into_response(setting::update_all(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_all(ctx)));
|
||||
|
||||
router.at("/ranking").nest(|router| {
|
||||
router
|
||||
.get(|ctx| into_response(setting::get_ranking(ctx)))
|
||||
.post(|ctx| into_response(setting::update_ranking(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_ranking(ctx)));
|
||||
|
||||
router
|
||||
.at("/rules")
|
||||
.get(|ctx| into_response(setting::get_rules(ctx)))
|
||||
.post(|ctx| into_response(setting::update_rules(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_rules(ctx)));
|
||||
|
||||
router
|
||||
.at("/distinct")
|
||||
.get(|ctx| into_response(setting::get_distinct(ctx)))
|
||||
.post(|ctx| into_response(setting::update_distinct(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_distinct(ctx)));
|
||||
});
|
||||
|
||||
router.at("/attributes").nest(|router| {
|
||||
router
|
||||
.get(|ctx| into_response(setting::get_attributes(ctx)))
|
||||
.post(|ctx| into_response(setting::update_attributes(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_attributes(ctx)));
|
||||
|
||||
router
|
||||
.at("/identifier")
|
||||
.get(|ctx| into_response(setting::get_identifier(ctx)));
|
||||
|
||||
router
|
||||
.at("/searchable")
|
||||
.get(|ctx| into_response(setting::get_searchable(ctx)))
|
||||
.post(|ctx| into_response(setting::update_searchable(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_searchable(ctx)));
|
||||
|
||||
router
|
||||
.at("/displayed")
|
||||
.get(|ctx| into_response(setting::get_displayed(ctx)))
|
||||
.post(|ctx| into_response(setting::update_displayed(ctx)))
|
||||
.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("/synonyms")
|
||||
.get(|ctx| into_response(synonym::get(ctx)))
|
||||
.post(|ctx| into_response(synonym::update(ctx)))
|
||||
.delete(|ctx| into_response(synonym::delete(ctx)));
|
||||
|
||||
router
|
||||
.at("/stop-words")
|
||||
.get(|ctx| into_response(stop_words::get(ctx)))
|
||||
.post(|ctx| into_response(stop_words::update(ctx)))
|
||||
.delete(|ctx| into_response(stop_words::delete(ctx)));
|
||||
});
|
||||
|
||||
router
|
||||
.at("/stats")
|
||||
.get(|ctx| into_response(stats::index_stat(ctx)));
|
||||
});
|
||||
});
|
||||
|
||||
router.at("/keys").nest(|router| {
|
||||
router
|
||||
.at("/")
|
||||
.get(|ctx| into_response(key::list(ctx)))
|
||||
.post(|ctx| into_response(key::create(ctx)));
|
||||
|
||||
router
|
||||
.at("/:key")
|
||||
.get(|ctx| into_response(key::get(ctx)))
|
||||
.put(|ctx| into_response(key::update(ctx)))
|
||||
.delete(|ctx| into_response(key::delete(ctx)));
|
||||
});
|
||||
app.at("/").get(|_| {
|
||||
async move {
|
||||
tide::Response::new(200)
|
||||
.body_string(include_str!("../../public/interface.html").to_string())
|
||||
.set_mime(mime::TEXT_HTML_UTF_8)
|
||||
}
|
||||
});
|
||||
app.at("/bulma.min.css").get(|_| {
|
||||
async {
|
||||
tide::Response::new(200)
|
||||
.body_string(include_str!("../../public/bulma.min.css").to_string())
|
||||
.set_mime(mime::TEXT_CSS_UTF_8)
|
||||
}
|
||||
});
|
||||
|
||||
app.at("").nest(|router| {
|
||||
router
|
||||
.at("/health")
|
||||
.get(|ctx| into_response(health::get_health(ctx)))
|
||||
.put(|ctx| into_response(health::change_healthyness(ctx)));
|
||||
app.at("/indexes/")
|
||||
.get(|ctx| into_response(index::list_indexes(ctx)))
|
||||
.post(|ctx| into_response(index::create_index(ctx)));
|
||||
|
||||
router
|
||||
.at("/stats")
|
||||
.get(|ctx| into_response(stats::get_stats(ctx)));
|
||||
router
|
||||
.at("/version")
|
||||
.get(|ctx| into_response(stats::get_version(ctx)));
|
||||
router
|
||||
.at("/sys-info")
|
||||
.get(|ctx| into_response(stats::get_sys_info(ctx)));
|
||||
router
|
||||
.at("/sys-info/pretty")
|
||||
.get(|ctx| into_response(stats::get_sys_info_pretty(ctx)));
|
||||
});
|
||||
app.at("/indexes/search")
|
||||
.post(|ctx| into_response(search::search_multi_index(ctx)));
|
||||
|
||||
app.at("/indexes/:index")
|
||||
.get(|ctx| into_response(index::get_index(ctx)))
|
||||
.put(|ctx| into_response(index::update_index(ctx)))
|
||||
.delete(|ctx| into_response(index::delete_index(ctx)));
|
||||
|
||||
app.at("/indexes/:index/search")
|
||||
.get(|ctx| into_response(search::search_with_url_query(ctx)));
|
||||
|
||||
app.at("/indexes/:index/updates")
|
||||
.get(|ctx| into_response(index::get_all_updates_status(ctx)));
|
||||
|
||||
app.at("/indexes/:index/updates/:update_id")
|
||||
.get(|ctx| into_response(index::get_update_status(ctx)));
|
||||
|
||||
app.at("/indexes/:index/documents")
|
||||
.get(|ctx| into_response(document::get_all_documents(ctx)))
|
||||
.post(|ctx| into_response(document::add_or_replace_multiple_documents(ctx)))
|
||||
.put(|ctx| into_response(document::add_or_update_multiple_documents(ctx)))
|
||||
.delete(|ctx| into_response(document::clear_all_documents(ctx)));
|
||||
|
||||
app.at("/indexes/:index/documents/:identifier")
|
||||
.get(|ctx| into_response(document::get_document(ctx)))
|
||||
.delete(|ctx| into_response(document::delete_document(ctx)));
|
||||
|
||||
app.at("/indexes/:index/documents/:identifier/delete-batch")
|
||||
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings")
|
||||
.get(|ctx| into_response(setting::get_all(ctx)))
|
||||
.post(|ctx| into_response(setting::update_all(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_all(ctx)));
|
||||
app.at("/indexes/:index/settings/ranking")
|
||||
.get(|ctx| into_response(setting::get_ranking(ctx)))
|
||||
.post(|ctx| into_response(setting::update_ranking(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_ranking(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/ranking/rules")
|
||||
.get(|ctx| into_response(setting::get_rules(ctx)))
|
||||
.post(|ctx| into_response(setting::update_rules(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_rules(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/ranking/distinct")
|
||||
.get(|ctx| into_response(setting::get_distinct(ctx)))
|
||||
.post(|ctx| into_response(setting::update_distinct(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_distinct(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/attributes")
|
||||
.get(|ctx| into_response(setting::get_attributes(ctx)))
|
||||
.post(|ctx| into_response(setting::update_attributes(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_attributes(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/attributes/identifier")
|
||||
.get(|ctx| into_response(setting::get_identifier(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/attributes/searchable")
|
||||
.get(|ctx| into_response(setting::get_searchable(ctx)))
|
||||
.post(|ctx| into_response(setting::update_searchable(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_searchable(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/attributes/displayed")
|
||||
.get(|ctx| into_response(setting::displayed(ctx)))
|
||||
.post(|ctx| into_response(setting::update_displayed(ctx)))
|
||||
.delete(|ctx| into_response(setting::delete_displayed(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/index-new-field")
|
||||
.get(|ctx| into_response(setting::get_index_new_fields(ctx)))
|
||||
.post(|ctx| into_response(setting::update_index_new_fields(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/synonyms")
|
||||
.get(|ctx| into_response(synonym::get(ctx)))
|
||||
.post(|ctx| into_response(synonym::update(ctx)))
|
||||
.delete(|ctx| into_response(synonym::delete(ctx)));
|
||||
|
||||
app.at("/indexes/:index/settings/stop_words")
|
||||
.get(|ctx| into_response(stop_words::get(ctx)))
|
||||
.post(|ctx| into_response(stop_words::update(ctx)))
|
||||
.delete(|ctx| into_response(stop_words::delete(ctx)));
|
||||
|
||||
app.at("/indexes/:index/stats")
|
||||
.get(|ctx| into_response(stats::index_stat(ctx)));
|
||||
|
||||
app.at("/keys/")
|
||||
.get(|ctx| into_response(key::list(ctx)))
|
||||
.post(|ctx| into_response(key::create(ctx)));
|
||||
|
||||
app.at("/keys/:key")
|
||||
.get(|ctx| into_response(key::get(ctx)))
|
||||
.put(|ctx| into_response(key::update(ctx)))
|
||||
.delete(|ctx| into_response(key::delete(ctx)));
|
||||
|
||||
app.at("/health")
|
||||
.get(|ctx| into_response(health::get_health(ctx)))
|
||||
.put(|ctx| into_response(health::change_healthyness(ctx)));
|
||||
|
||||
app.at("/stats")
|
||||
.get(|ctx| into_response(stats::get_stats(ctx)));
|
||||
|
||||
app.at("/version")
|
||||
.get(|ctx| into_response(stats::get_version(ctx)));
|
||||
|
||||
app.at("/sys-info")
|
||||
.get(|ctx| into_response(stats::get_sys_info(ctx)));
|
||||
|
||||
app.at("/sys-info/pretty")
|
||||
.get(|ctx| into_response(stats::get_sys_info_pretty(ctx)));
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ pub async fn search_with_url_query(ctx: Request<Data>) -> SResult<Response> {
|
|||
let crop_length = query.crop_length.unwrap_or(200);
|
||||
if attributes_to_crop == "*" {
|
||||
let attributes_to_crop = schema
|
||||
.get_displayed_name()
|
||||
.displayed_name()
|
||||
.iter()
|
||||
.map(|attr| (attr.to_string(), crop_length))
|
||||
.collect();
|
||||
|
@ -78,11 +78,15 @@ pub async fn search_with_url_query(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
if let Some(attributes_to_highlight) = query.attributes_to_highlight {
|
||||
let attributes_to_highlight = if attributes_to_highlight == "*" {
|
||||
schema.get_displayed_name()
|
||||
schema
|
||||
.displayed_name()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
} else {
|
||||
attributes_to_highlight
|
||||
.split(',')
|
||||
.map(ToString::to_string)
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
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();
|
||||
let stop_words = if stop_words.len() > 0 {
|
||||
let stop_words = if stop_words.is_empty() {
|
||||
Some(stop_words)
|
||||
} else {
|
||||
None
|
||||
|
@ -40,7 +40,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
}
|
||||
}
|
||||
|
||||
let synonyms = if synonyms.len() > 0 {
|
||||
let synonyms = if synonyms.is_empty() {
|
||||
Some(synonyms)
|
||||
} else {
|
||||
None
|
||||
|
@ -54,17 +54,21 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
||||
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
||||
let attributes_displayed = schema.clone().map(|s| s.get_displayed_name());
|
||||
let index_new_fields = schema.map(|s| s.must_index_new_fields());
|
||||
let identifier = schema.clone().map(|s| s.identifier().to_owned());
|
||||
let searchable_attributes = schema
|
||||
.clone()
|
||||
.map(|s| s.indexed_name().iter().map(|s| s.to_string()).collect());
|
||||
let displayed_attributes = schema
|
||||
.clone()
|
||||
.map(|s| s.displayed_name().iter().map(|s| s.to_string()).collect());
|
||||
let index_new_fields = schema.map(|s| s.index_new_fields());
|
||||
|
||||
let settings = Settings {
|
||||
ranking_rules: Some(ranking_rules),
|
||||
ranking_distinct: Some(ranking_distinct),
|
||||
attribute_identifier: Some(attribute_identifier),
|
||||
attributes_searchable: Some(attributes_searchable),
|
||||
attributes_displayed: Some(attributes_displayed),
|
||||
identifier: Some(identifier),
|
||||
searchable_attributes: Some(searchable_attributes),
|
||||
displayed_attributes: Some(displayed_attributes),
|
||||
stop_words: Some(stop_words),
|
||||
synonyms: Some(synonyms),
|
||||
index_new_fields: Some(index_new_fields),
|
||||
|
@ -78,9 +82,9 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
pub struct UpdateSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
pub ranking_distinct: Option<String>,
|
||||
pub attribute_identifier: Option<String>,
|
||||
pub attributes_searchable: Option<Vec<String>>,
|
||||
pub attributes_displayed: Option<HashSet<String>>,
|
||||
pub identifier: 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 index_new_fields: Option<bool>,
|
||||
|
@ -96,20 +100,20 @@ 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),
|
||||
attribute_identifier: Some(settings_update.attribute_identifier),
|
||||
attributes_searchable: Some(settings_update.attributes_searchable),
|
||||
attributes_displayed: Some(settings_update.attributes_displayed),
|
||||
identifier: Some(settings_update.identifier),
|
||||
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),
|
||||
index_new_fields: Some(settings_update.index_new_fields),
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -121,9 +125,9 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
let settings = SettingsUpdate {
|
||||
ranking_rules: UpdateState::Clear,
|
||||
ranking_distinct: UpdateState::Clear,
|
||||
attribute_identifier: UpdateState::Clear,
|
||||
attributes_searchable: UpdateState::Clear,
|
||||
attributes_displayed: UpdateState::Clear,
|
||||
identifier: UpdateState::Clear,
|
||||
searchable_attributes: UpdateState::Clear,
|
||||
displayed_attributes: UpdateState::Clear,
|
||||
stop_words: UpdateState::Clear,
|
||||
synonyms: UpdateState::Clear,
|
||||
index_new_fields: UpdateState::Clear,
|
||||
|
@ -134,12 +138,12 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct GetRankingSettings {
|
||||
pub struct RankingSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
pub ranking_distinct: Option<String>,
|
||||
}
|
||||
|
@ -156,7 +160,7 @@ pub async fn get_ranking(ctx: Request<Data>) -> SResult<Response> {
|
|||
};
|
||||
|
||||
let ranking_distinct = index.main.ranking_distinct(&reader)?;
|
||||
let settings = GetRankingSettings {
|
||||
let settings = RankingSettings {
|
||||
ranking_rules,
|
||||
ranking_distinct,
|
||||
};
|
||||
|
@ -164,17 +168,10 @@ pub async fn get_ranking(ctx: Request<Data>) -> SResult<Response> {
|
|||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SetRankingSettings {
|
||||
pub ranking_rules: Option<Vec<String>>,
|
||||
pub ranking_distinct: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn update_ranking(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: SetRankingSettings = ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let settings: RankingSettings = ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
|
@ -184,11 +181,11 @@ pub async fn update_ranking(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_ranking(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -208,7 +205,7 @@ pub async fn delete_ranking(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -238,11 +235,11 @@ pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -261,13 +258,7 @@ pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct GetRankingDistinctSettings {
|
||||
pub ranking_distinct: Option<String>,
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -283,12 +274,6 @@ pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
|||
.unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SetRankingDistinctSettings {
|
||||
pub ranking_distinct: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
|
@ -302,11 +287,11 @@ pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -325,15 +310,15 @@ pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct GetAttributesSettings {
|
||||
pub attribute_identifier: Option<String>,
|
||||
pub attributes_searchable: Option<Vec<String>>,
|
||||
pub attributes_displayed: Option<HashSet<String>>,
|
||||
pub struct AttributesSettings {
|
||||
pub identifier: Option<String>,
|
||||
pub searchable_attributes: Option<Vec<String>>,
|
||||
pub displayed_attributes: Option<HashSet<String>>,
|
||||
}
|
||||
|
||||
pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -344,47 +329,42 @@ pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
||||
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
||||
let attributes_displayed = schema.clone().map(|s| s.get_displayed_name());
|
||||
let identifier = schema.clone().map(|s| s.identifier().to_string());
|
||||
let searchable_attributes = schema
|
||||
.clone()
|
||||
.map(|s| s.indexed_name().iter().map(|s| s.to_string()).collect());
|
||||
let displayed_attributes = schema
|
||||
.clone()
|
||||
.map(|s| s.displayed_name().iter().map(|s| s.to_string()).collect());
|
||||
|
||||
let settings = GetAttributesSettings {
|
||||
attribute_identifier,
|
||||
attributes_searchable,
|
||||
attributes_displayed,
|
||||
let settings = AttributesSettings {
|
||||
identifier,
|
||||
searchable_attributes,
|
||||
displayed_attributes,
|
||||
};
|
||||
|
||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SetAttributesSettings {
|
||||
pub attribute_identifier: Option<String>,
|
||||
pub attributes_searchable: Option<Vec<String>>,
|
||||
pub attributes_displayed: Option<HashSet<String>>,
|
||||
}
|
||||
|
||||
pub async fn update_attributes(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let settings: SetAttributesSettings =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let settings: AttributesSettings = ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
attribute_identifier: Some(settings.attribute_identifier),
|
||||
attributes_searchable: Some(settings.attributes_searchable),
|
||||
attributes_displayed: Some(settings.attributes_displayed),
|
||||
identifier: Some(settings.identifier),
|
||||
searchable_attributes: Some(settings.searchable_attributes),
|
||||
displayed_attributes: Some(settings.displayed_attributes),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_attributes(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -393,8 +373,8 @@ pub async fn delete_attributes(ctx: Request<Data>) -> SResult<Response> {
|
|||
let db = &ctx.state().db;
|
||||
|
||||
let settings = SettingsUpdate {
|
||||
attributes_searchable: UpdateState::Clear,
|
||||
attributes_displayed: UpdateState::Clear,
|
||||
searchable_attributes: UpdateState::Clear,
|
||||
displayed_attributes: UpdateState::Clear,
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -403,7 +383,7 @@ pub async fn delete_attributes(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -414,11 +394,9 @@ pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let attribute_identifier = schema.map(|s| s.identifier());
|
||||
let identifier = schema.map(|s| s.identifier().to_string());
|
||||
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attribute_identifier)
|
||||
.unwrap())
|
||||
Ok(tide::Response::new(200).body_json(&identifier).unwrap())
|
||||
}
|
||||
|
||||
pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -429,37 +407,32 @@ pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let attributes_searchable = schema.map(|s| s.get_indexed_name());
|
||||
let searchable_attributes: Option<HashSet<String>> =
|
||||
schema.map(|s| s.indexed_name().iter().map(|i| i.to_string()).collect());
|
||||
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attributes_searchable)
|
||||
.body_json(&searchable_attributes)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct SetAttributesSearchableSettings {
|
||||
pub attributes_searchable: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let attributes_searchable: Option<Vec<String>> =
|
||||
let searchable_attributes: Option<Vec<String>> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
attributes_searchable: Some(attributes_searchable),
|
||||
searchable_attributes: Some(searchable_attributes),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -468,7 +441,7 @@ pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
|||
let db = &ctx.state().db;
|
||||
|
||||
let settings = SettingsUpdate {
|
||||
attributes_searchable: UpdateState::Clear,
|
||||
searchable_attributes: UpdateState::Clear,
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -477,10 +450,10 @@ pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsRead)?;
|
||||
let index = ctx.index()?;
|
||||
let db = &ctx.state().db;
|
||||
|
@ -488,31 +461,32 @@ pub async fn get_displayed(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let attributes_displayed = schema.map(|s| s.get_displayed_name());
|
||||
let displayed_attributes: Option<HashSet<String>> =
|
||||
schema.map(|s| s.displayed_name().iter().map(|i| i.to_string()).collect());
|
||||
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&attributes_displayed)
|
||||
.body_json(&displayed_attributes)
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(SettingsWrite)?;
|
||||
let index = ctx.index()?;
|
||||
let attributes_displayed: Option<HashSet<String>> =
|
||||
let displayed_attributes: Option<HashSet<String>> =
|
||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||
let db = &ctx.state().db;
|
||||
|
||||
let settings = Settings {
|
||||
attributes_displayed: Some(attributes_displayed),
|
||||
displayed_attributes: Some(displayed_attributes),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -521,7 +495,7 @@ pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
|||
let db = &ctx.state().db;
|
||||
|
||||
let settings = SettingsUpdate {
|
||||
attributes_displayed: UpdateState::Clear,
|
||||
displayed_attributes: UpdateState::Clear,
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -530,7 +504,7 @@ pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn get_index_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -541,7 +515,7 @@ pub async fn get_index_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
|||
|
||||
let schema = index.main.schema(&reader)?;
|
||||
|
||||
let index_new_fields = schema.map(|s| s.must_index_new_fields());
|
||||
let index_new_fields = schema.map(|s| s.index_new_fields());
|
||||
|
||||
Ok(tide::Response::new(200)
|
||||
.body_json(&index_new_fields)
|
||||
|
@ -561,9 +535,9 @@ pub async fn update_index_new_fields(mut ctx: Request<Data>) -> SResult<Response
|
|||
};
|
||||
|
||||
let mut writer = db.update_write_txn()?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into())?;
|
||||
let update_id = index.settings_update(&mut writer, settings.into_update()?)?;
|
||||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub async fn update(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -59,5 +59,5 @@ pub async fn delete(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub async fn update(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
||||
pub async fn delete(ctx: Request<Data>) -> SResult<Response> {
|
||||
|
@ -78,5 +78,5 @@ pub async fn delete(ctx: Request<Data>) -> SResult<Response> {
|
|||
writer.commit()?;
|
||||
|
||||
let response_body = IndexUpdateResponse { update_id };
|
||||
Ok(tide::Response::new(202).body_json(&response_body).unwrap())
|
||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue