mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-25 22:34:28 +01:00
change param tuples by struct
add settings endpoint; wip
This commit is contained in:
parent
5ec130e6dc
commit
b08f6737ac
@ -7,25 +7,31 @@ use actix_web as aweb;
|
|||||||
|
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
use crate::routes::IndexUpdateResponse;
|
use crate::routes::{IndexUpdateResponse, IndexParam};
|
||||||
|
|
||||||
type Document = IndexMap<String, Value>;
|
type Document = IndexMap<String, Value>;
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize)]
|
||||||
|
pub struct DocumentParam {
|
||||||
|
index_uid: String,
|
||||||
|
document_id: String
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/documents/{document_id}")]
|
#[get("/indexes/{index_uid}/documents/{document_id}")]
|
||||||
pub async fn get_document(
|
pub async fn get_document(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<(String, String)>,
|
path: web::Path<DocumentParam>,
|
||||||
) -> aweb::Result<web::Json<Document>> {
|
) -> aweb::Result<web::Json<Document>> {
|
||||||
let index = data.db.open_index(&path.0)
|
let index = data.db.open_index(&path.index_uid)
|
||||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
let document_id = meilisearch_core::serde::compute_document_id(path.1.clone());
|
let document_id = meilisearch_core::serde::compute_document_id(path.document_id.clone());
|
||||||
|
|
||||||
let reader = data.db.main_read_txn()
|
let reader = data.db.main_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let response = index.document::<Document, String>(&reader, None, document_id)
|
let response = index.document::<Document, String>(&reader, None, document_id)
|
||||||
.map_err(|_| ResponseError::DocumentNotFound(path.1.clone()))?
|
.map_err(|_| ResponseError::DocumentNotFound(path.document_id.clone()))?
|
||||||
.ok_or(ResponseError::DocumentNotFound(path.1.clone()))?;
|
.ok_or(ResponseError::DocumentNotFound(path.document_id.clone()))?;
|
||||||
|
|
||||||
Ok(web::Json(response))
|
Ok(web::Json(response))
|
||||||
}
|
}
|
||||||
@ -33,11 +39,11 @@ pub async fn get_document(
|
|||||||
#[delete("/indexes/{index_uid}/documents/{document_id}")]
|
#[delete("/indexes/{index_uid}/documents/{document_id}")]
|
||||||
pub async fn delete_document(
|
pub async fn delete_document(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<(String, String)>,
|
path: web::Path<DocumentParam>,
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
let index = data.db.open_index(&path.0)
|
let index = data.db.open_index(&path.index_uid)
|
||||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
let document_id = meilisearch_core::serde::compute_document_id(path.1.clone());
|
let document_id = meilisearch_core::serde::compute_document_id(path.document_id.clone());
|
||||||
|
|
||||||
let mut update_writer = data.db.update_write_txn()
|
let mut update_writer = data.db.update_write_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -66,12 +72,12 @@ pub struct BrowseQuery {
|
|||||||
#[get("/indexes/{index_uid}/documents")]
|
#[get("/indexes/{index_uid}/documents")]
|
||||||
pub async fn get_all_documents(
|
pub async fn get_all_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
params: web::Query<BrowseQuery>,
|
params: web::Query<BrowseQuery>,
|
||||||
) -> aweb::Result<web::Json<Vec<Document>>> {
|
) -> aweb::Result<web::Json<Vec<Document>>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(&path.index_uid)
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let offset = params.offset.unwrap_or(0);
|
let offset = params.offset.unwrap_or(0);
|
||||||
let limit = params.limit.unwrap_or(20);
|
let limit = params.limit.unwrap_or(20);
|
||||||
@ -82,7 +88,7 @@ pub async fn get_all_documents(
|
|||||||
let documents_ids: Result<BTreeSet<_>, _> = index
|
let documents_ids: Result<BTreeSet<_>, _> = index
|
||||||
.documents_fields_counts
|
.documents_fields_counts
|
||||||
.documents_ids(&reader)
|
.documents_ids(&reader)
|
||||||
.map_err(|_| ResponseError::Internal(path.clone()))?
|
.map_err(|_| ResponseError::Internal(path.index_uid.clone()))?
|
||||||
.skip(offset)
|
.skip(offset)
|
||||||
.take(limit)
|
.take(limit)
|
||||||
.collect();
|
.collect();
|
||||||
@ -120,14 +126,14 @@ pub struct UpdateDocumentsQuery {
|
|||||||
|
|
||||||
async fn update_multiple_documents(
|
async fn update_multiple_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
params: web::Query<UpdateDocumentsQuery>,
|
params: web::Query<UpdateDocumentsQuery>,
|
||||||
body: web::Json<Vec<Document>>,
|
body: web::Json<Vec<Document>>,
|
||||||
is_partial: bool
|
is_partial: bool
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.main_read_txn()
|
let reader = data.db.main_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -182,7 +188,7 @@ async fn update_multiple_documents(
|
|||||||
#[post("/indexes/{index_uid}/documents")]
|
#[post("/indexes/{index_uid}/documents")]
|
||||||
pub async fn add_documents(
|
pub async fn add_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
params: web::Query<UpdateDocumentsQuery>,
|
params: web::Query<UpdateDocumentsQuery>,
|
||||||
body: web::Json<Vec<Document>>
|
body: web::Json<Vec<Document>>
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
@ -192,7 +198,7 @@ pub async fn add_documents(
|
|||||||
#[put("/indexes/{index_uid}/documents")]
|
#[put("/indexes/{index_uid}/documents")]
|
||||||
pub async fn update_documents(
|
pub async fn update_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
params: web::Query<UpdateDocumentsQuery>,
|
params: web::Query<UpdateDocumentsQuery>,
|
||||||
body: web::Json<Vec<Document>>
|
body: web::Json<Vec<Document>>
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
@ -202,12 +208,12 @@ pub async fn update_documents(
|
|||||||
#[post("/indexes/{index_uid}/documents/delete-batch")]
|
#[post("/indexes/{index_uid}/documents/delete-batch")]
|
||||||
pub async fn delete_documents(
|
pub async fn delete_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<Vec<Value>>
|
body: web::Json<Vec<Value>>
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let mut writer = data.db.update_write_txn()
|
let mut writer = data.db.update_write_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -233,11 +239,11 @@ pub async fn delete_documents(
|
|||||||
#[delete("/indexes/{index_uid}/documents")]
|
#[delete("/indexes/{index_uid}/documents")]
|
||||||
pub async fn clear_all_documents(
|
pub async fn clear_all_documents(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let mut writer = data.db.update_write_txn()
|
let mut writer = data.db.update_write_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
@ -8,6 +8,7 @@ use meilisearch_core::UpdateStatus;
|
|||||||
|
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
use crate::routes::IndexParam;
|
||||||
|
|
||||||
fn generate_uid() -> String {
|
fn generate_uid() -> String {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
@ -83,11 +84,11 @@ pub async fn list_indexes(
|
|||||||
#[get("/indexes/{index_uid}")]
|
#[get("/indexes/{index_uid}")]
|
||||||
pub async fn get_index(
|
pub async fn get_index(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<web::Json<IndexResponse>> {
|
) -> aweb::Result<web::Json<IndexResponse>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.main_read_txn()
|
let reader = data.db.main_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -112,7 +113,7 @@ pub async fn get_index(
|
|||||||
|
|
||||||
Ok(web::Json(IndexResponse {
|
Ok(web::Json(IndexResponse {
|
||||||
name,
|
name,
|
||||||
uid: path.to_string(),
|
uid: path.index_uid.clone(),
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
primary_key,
|
primary_key,
|
||||||
@ -220,12 +221,12 @@ pub struct UpdateIndexResponse {
|
|||||||
#[post("/indexes/{index_uid}")]
|
#[post("/indexes/{index_uid}")]
|
||||||
pub async fn update_index(
|
pub async fn update_index(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<IndexCreateRequest>
|
body: web::Json<IndexCreateRequest>
|
||||||
) -> aweb::Result<web::Json<IndexResponse>> {
|
) -> aweb::Result<web::Json<IndexResponse>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let mut writer = data.db.main_write_txn()
|
let mut writer = data.db.main_write_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -281,7 +282,7 @@ pub async fn update_index(
|
|||||||
|
|
||||||
Ok(web::Json(IndexResponse {
|
Ok(web::Json(IndexResponse {
|
||||||
name,
|
name,
|
||||||
uid: path.clone(),
|
uid: path.index_uid.clone(),
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
primary_key,
|
primary_key,
|
||||||
@ -291,45 +292,50 @@ pub async fn update_index(
|
|||||||
#[delete("/indexes/{index_uid}")]
|
#[delete("/indexes/{index_uid}")]
|
||||||
pub async fn delete_index(
|
pub async fn delete_index(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<HttpResponse> {
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
|
||||||
data.db.delete_index(&path.to_string())
|
data.db.delete_index(&path.index_uid)
|
||||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
HttpResponse::NoContent().await
|
HttpResponse::NoContent().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize)]
|
||||||
|
pub struct UpdateParam {
|
||||||
|
index_uid: String,
|
||||||
|
update_id: u64
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/updates/{update_id}")]
|
#[get("/indexes/{index_uid}/updates/{update_id}")]
|
||||||
pub async fn get_update_status(
|
pub async fn get_update_status(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<(String, u64)>,
|
path: web::Path<UpdateParam>,
|
||||||
) -> aweb::Result<web::Json<UpdateStatus>> {
|
) -> aweb::Result<web::Json<UpdateStatus>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.0.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.update_read_txn()
|
let reader = data.db.update_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let status = index.update_status(&reader, path.1)
|
let status = index.update_status(&reader, path.update_id)
|
||||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
match status {
|
match status {
|
||||||
Some(status) => Ok(web::Json(status)),
|
Some(status) => Ok(web::Json(status)),
|
||||||
None => Err(ResponseError::NotFound(format!("Update {} not found", path.1)).into())
|
None => Err(ResponseError::NotFound(format!("Update {} not found", path.update_id)).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/indexes/{index_uid}/updates")]
|
#[get("/indexes/{index_uid}/updates")]
|
||||||
pub async fn get_all_updates_status(
|
pub async fn get_all_updates_status(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<web::Json<Vec<UpdateStatus>>> {
|
) -> aweb::Result<web::Json<Vec<UpdateStatus>>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.update_read_txn()
|
let reader = data.db.update_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use actix_web::{get, HttpResponse};
|
use actix_web::{get, HttpResponse};
|
||||||
use serde::Serialize;
|
use serde::{Serialize, Deserialize};
|
||||||
use log::error;
|
use log::error;
|
||||||
use meilisearch_core::ProcessedUpdateResult;
|
use meilisearch_core::ProcessedUpdateResult;
|
||||||
|
|
||||||
@ -11,10 +11,15 @@ pub mod index;
|
|||||||
pub mod key;
|
pub mod key;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod stats;
|
pub mod stats;
|
||||||
// pub mod setting;
|
pub mod setting;
|
||||||
// pub mod stop_words;
|
// pub mod stop_words;
|
||||||
// pub mod synonym;
|
// pub mod synonym;
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize)]
|
||||||
|
pub struct IndexParam {
|
||||||
|
index_uid: String
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Serialize)]
|
#[derive(Default, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct IndexUpdateResponse {
|
pub struct IndexUpdateResponse {
|
||||||
|
@ -12,6 +12,7 @@ use actix_web as aweb;
|
|||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
use crate::helpers::meilisearch::{Error, IndexSearchExt, SearchHit, SearchResult};
|
use crate::helpers::meilisearch::{Error, IndexSearchExt, SearchHit, SearchResult};
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
use crate::routes::IndexParam;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
@ -31,12 +32,12 @@ pub struct SearchQuery {
|
|||||||
#[get("/indexes/{index_uid}/search")]
|
#[get("/indexes/{index_uid}/search")]
|
||||||
pub async fn search_with_url_query(
|
pub async fn search_with_url_query(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
params: web::Query<SearchQuery>,
|
params: web::Query<SearchQuery>,
|
||||||
) -> aweb::Result<web::Json<SearchResult>> {
|
) -> aweb::Result<web::Json<SearchResult>> {
|
||||||
|
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.main_read_txn()
|
let reader = data.db.main_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
@ -1,47 +1,61 @@
|
|||||||
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 tide::{Request, Response};
|
use actix_web::{web, get, post, put, delete, HttpResponse};
|
||||||
|
use actix_web as aweb;
|
||||||
|
|
||||||
use crate::error::{ResponseError, SResult};
|
use crate::error::{ResponseError};
|
||||||
use crate::helpers::tide::RequestExt;
|
|
||||||
use crate::helpers::tide::ACL::*;
|
|
||||||
use crate::routes::document::IndexUpdateResponse;
|
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
use crate::routes::{IndexUpdateResponse, IndexParam};
|
||||||
|
|
||||||
pub async fn get_all(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 db = &ctx.state().db;
|
path: web::Path<IndexParam>,
|
||||||
let reader = db.main_read_txn()?;
|
) -> aweb::Result<HttpResponse> {
|
||||||
|
let index = data.db.open_index(&path.index_uid)
|
||||||
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let stop_words_fst = index.main.stop_words_fst(&reader)?;
|
let reader = data.db.main_read_txn()
|
||||||
let stop_words = stop_words_fst.unwrap_or_default().stream().into_strs()?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
|
let stop_words_fst = index.main.stop_words_fst(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
let stop_words = stop_words_fst.unwrap_or_default().stream().into_strs()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
let stop_words: BTreeSet<String> = stop_words.into_iter().collect();
|
let stop_words: BTreeSet<String> = stop_words.into_iter().collect();
|
||||||
|
|
||||||
let synonyms_fst = index.main.synonyms_fst(&reader)?.unwrap_or_default();
|
let synonyms_fst = index.main.synonyms_fst(&reader)
|
||||||
let synonyms_list = synonyms_fst.stream().into_strs()?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||||
|
.unwrap_or_default();
|
||||||
|
let synonyms_list = synonyms_fst.stream().into_strs()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let mut synonyms = BTreeMap::new();
|
let mut synonyms = BTreeMap::new();
|
||||||
let index_synonyms = &index.synonyms;
|
let index_synonyms = &index.synonyms;
|
||||||
for synonym in synonyms_list {
|
for synonym in synonyms_list {
|
||||||
let alternative_list = index_synonyms.synonyms(&reader, synonym.as_bytes())?;
|
let alternative_list = index_synonyms.synonyms(&reader, synonym.as_bytes())
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
if let Some(list) = alternative_list {
|
if let Some(list) = alternative_list {
|
||||||
let list = list.stream().into_strs()?;
|
let list = list.stream().into_strs()
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
synonyms.insert(synonym, list);
|
synonyms.insert(synonym, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ranking_rules = index
|
let ranking_rules = index
|
||||||
.main
|
.main
|
||||||
.ranking_rules(&reader)?
|
.ranking_rules(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||||
.unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
.unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|r| r.to_string())
|
.map(|r| r.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
let distinct_attribute = index.main.distinct_attribute(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let schema = index.main.schema(&reader)?;
|
let schema = index.main.schema(&reader)
|
||||||
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let searchable_attributes = schema.clone().map(|s| {
|
let searchable_attributes = schema.clone().map(|s| {
|
||||||
s.indexed_name()
|
s.indexed_name()
|
||||||
@ -69,306 +83,306 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
accept_new_fields: Some(accept_new_fields),
|
accept_new_fields: Some(accept_new_fields),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
Ok(HttpResponse::Ok().json(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let settings: Settings =
|
// let settings: Settings =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
|
|
||||||
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)?;
|
||||||
|
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let reader = db.main_read_txn()?;
|
// let reader = db.main_read_txn()?;
|
||||||
|
|
||||||
let ranking_rules = index
|
// let ranking_rules = index
|
||||||
.main
|
// .main
|
||||||
.ranking_rules(&reader)?
|
// .ranking_rules(&reader)?
|
||||||
.unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
// .unwrap_or(DEFAULT_RANKING_RULES.to_vec())
|
||||||
.into_iter()
|
// .into_iter()
|
||||||
.map(|r| r.to_string())
|
// .map(|r| r.to_string())
|
||||||
.collect::<Vec<String>>();
|
// .collect::<Vec<String>>();
|
||||||
|
|
||||||
Ok(tide::Response::new(200).body_json(&ranking_rules).unwrap())
|
// Ok(tide::Response::new(200).body_json(&ranking_rules).unwrap())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let ranking_rules: Option<Vec<String>> =
|
// let ranking_rules: Option<Vec<String>> =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
// let settings = Settings {
|
||||||
ranking_rules: Some(ranking_rules),
|
// ranking_rules: Some(ranking_rules),
|
||||||
..Settings::default()
|
// ..Settings::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
// let settings = SettingsUpdate {
|
||||||
ranking_rules: UpdateState::Clear,
|
// ranking_rules: UpdateState::Clear,
|
||||||
..SettingsUpdate::default()
|
// ..SettingsUpdate::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
|
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let reader = db.main_read_txn()?;
|
// let reader = db.main_read_txn()?;
|
||||||
|
|
||||||
let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
// let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
||||||
|
|
||||||
Ok(tide::Response::new(200)
|
// Ok(tide::Response::new(200)
|
||||||
.body_json(&distinct_attribute)
|
// .body_json(&distinct_attribute)
|
||||||
.unwrap())
|
// .unwrap())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let distinct_attribute: Option<String> =
|
// let distinct_attribute: Option<String> =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
// let settings = Settings {
|
||||||
distinct_attribute: Some(distinct_attribute),
|
// distinct_attribute: Some(distinct_attribute),
|
||||||
..Settings::default()
|
// ..Settings::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
// let settings = SettingsUpdate {
|
||||||
distinct_attribute: UpdateState::Clear,
|
// distinct_attribute: UpdateState::Clear,
|
||||||
..SettingsUpdate::default()
|
// ..SettingsUpdate::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
|
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let reader = db.main_read_txn()?;
|
// let reader = db.main_read_txn()?;
|
||||||
|
|
||||||
let schema = index.main.schema(&reader)?;
|
// let schema = index.main.schema(&reader)?;
|
||||||
|
|
||||||
let searchable_attributes: Option<Vec<String>> =
|
// let searchable_attributes: Option<Vec<String>> =
|
||||||
schema.map(|s| s.indexed_name().iter().map(|i| (*i).to_string()).collect());
|
// schema.map(|s| s.indexed_name().iter().map(|i| (*i).to_string()).collect());
|
||||||
|
|
||||||
Ok(tide::Response::new(200)
|
// Ok(tide::Response::new(200)
|
||||||
.body_json(&searchable_attributes)
|
// .body_json(&searchable_attributes)
|
||||||
.unwrap())
|
// .unwrap())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let searchable_attributes: Option<Vec<String>> =
|
// let searchable_attributes: Option<Vec<String>> =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
// let settings = Settings {
|
||||||
searchable_attributes: Some(searchable_attributes),
|
// searchable_attributes: Some(searchable_attributes),
|
||||||
..Settings::default()
|
// ..Settings::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
// let settings = SettingsUpdate {
|
||||||
searchable_attributes: UpdateState::Clear,
|
// searchable_attributes: UpdateState::Clear,
|
||||||
..SettingsUpdate::default()
|
// ..SettingsUpdate::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let reader = db.main_read_txn()?;
|
// let reader = db.main_read_txn()?;
|
||||||
|
|
||||||
let schema = index.main.schema(&reader)?;
|
// let schema = index.main.schema(&reader)?;
|
||||||
|
|
||||||
let displayed_attributes: Option<HashSet<String>> = schema.map(|s| {
|
// let displayed_attributes: Option<HashSet<String>> = schema.map(|s| {
|
||||||
s.displayed_name()
|
// s.displayed_name()
|
||||||
.iter()
|
// .iter()
|
||||||
.map(|i| (*i).to_string())
|
// .map(|i| (*i).to_string())
|
||||||
.collect()
|
// .collect()
|
||||||
});
|
// });
|
||||||
|
|
||||||
Ok(tide::Response::new(200)
|
// Ok(tide::Response::new(200)
|
||||||
.body_json(&displayed_attributes)
|
// .body_json(&displayed_attributes)
|
||||||
.unwrap())
|
// .unwrap())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let displayed_attributes: Option<HashSet<String>> =
|
// let displayed_attributes: Option<HashSet<String>> =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
// let settings = Settings {
|
||||||
displayed_attributes: Some(displayed_attributes),
|
// displayed_attributes: Some(displayed_attributes),
|
||||||
..Settings::default()
|
// ..Settings::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn delete_displayed(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = SettingsUpdate {
|
// let settings = SettingsUpdate {
|
||||||
displayed_attributes: UpdateState::Clear,
|
// displayed_attributes: UpdateState::Clear,
|
||||||
..SettingsUpdate::default()
|
// ..SettingsUpdate::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn get_accept_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn get_accept_new_fields(ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
let reader = db.main_read_txn()?;
|
// let reader = db.main_read_txn()?;
|
||||||
|
|
||||||
let schema = index.main.schema(&reader)?;
|
// let schema = index.main.schema(&reader)?;
|
||||||
|
|
||||||
let accept_new_fields = schema.map(|s| s.accept_new_fields());
|
// let accept_new_fields = schema.map(|s| s.accept_new_fields());
|
||||||
|
|
||||||
Ok(tide::Response::new(200)
|
// Ok(tide::Response::new(200)
|
||||||
.body_json(&accept_new_fields)
|
// .body_json(&accept_new_fields)
|
||||||
.unwrap())
|
// .unwrap())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn update_accept_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
|
// pub async fn update_accept_new_fields(mut ctx: Request<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(Private)?;
|
// ctx.is_allowed(Private)?;
|
||||||
let index = ctx.index()?;
|
// let index = ctx.index()?;
|
||||||
let accept_new_fields: Option<bool> =
|
// let accept_new_fields: Option<bool> =
|
||||||
ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
// ctx.body_json().await.map_err(ResponseError::bad_request)?;
|
||||||
let db = &ctx.state().db;
|
// let db = &ctx.state().db;
|
||||||
|
|
||||||
let settings = Settings {
|
// let settings = Settings {
|
||||||
accept_new_fields: Some(accept_new_fields),
|
// accept_new_fields: Some(accept_new_fields),
|
||||||
..Settings::default()
|
// ..Settings::default()
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mut writer = db.update_write_txn()?;
|
// let mut writer = db.update_write_txn()?;
|
||||||
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
// let settings = settings.into_update().map_err(ResponseError::bad_request)?;
|
||||||
let update_id = index.settings_update(&mut writer, settings)?;
|
// let update_id = index.settings_update(&mut writer, settings)?;
|
||||||
writer.commit()?;
|
// writer.commit()?;
|
||||||
|
|
||||||
let response_body = IndexUpdateResponse { update_id };
|
// let response_body = IndexUpdateResponse { update_id };
|
||||||
Ok(tide::Response::new(202).body_json(&response_body)?)
|
// Ok(tide::Response::new(202).body_json(&response_body)?)
|
||||||
}
|
// }
|
||||||
|
@ -11,6 +11,7 @@ use walkdir::WalkDir;
|
|||||||
|
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
|
use crate::routes::IndexParam;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@ -23,10 +24,10 @@ pub struct IndexStatsResponse {
|
|||||||
#[get("/indexes/{index_uid}/stats")]
|
#[get("/indexes/{index_uid}/stats")]
|
||||||
pub async fn index_stats(
|
pub async fn index_stats(
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
path: web::Path<String>,
|
path: web::Path<IndexParam>,
|
||||||
) -> aweb::Result<web::Json<IndexStatsResponse>> {
|
) -> aweb::Result<web::Json<IndexStatsResponse>> {
|
||||||
let index = data.db.open_index(path.clone())
|
let index = data.db.open_index(path.index_uid.clone())
|
||||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
|
||||||
|
|
||||||
let reader = data.db.main_read_txn()
|
let reader = data.db.main_read_txn()
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
@ -42,7 +43,7 @@ pub async fn index_stats(
|
|||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let is_indexing = data
|
let is_indexing = data
|
||||||
.is_indexing(&update_reader, &path)
|
.is_indexing(&update_reader, &path.index_uid)
|
||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user