mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
cleanup
This commit is contained in:
parent
6c581fb3bd
commit
5ec130e6dc
11 changed files with 122 additions and 140 deletions
|
@ -2,7 +2,8 @@ use std::collections::BTreeSet;
|
|||
use indexmap::IndexMap;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use actix_web::*;
|
||||
use actix_web::{web, get, post, put, delete, HttpResponse};
|
||||
use actix_web as aweb;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::Data;
|
||||
|
@ -14,13 +15,13 @@ type Document = IndexMap<String, Value>;
|
|||
pub async fn get_document(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<(String, String)>,
|
||||
) -> Result<web::Json<Document>> {
|
||||
) -> aweb::Result<web::Json<Document>> {
|
||||
let index = data.db.open_index(&path.0)
|
||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
||||
let document_id = meilisearch_core::serde::compute_document_id(path.1.clone());
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let response = index.document::<Document, String>(&reader, None, document_id)
|
||||
.map_err(|_| ResponseError::DocumentNotFound(path.1.clone()))?
|
||||
|
@ -33,13 +34,13 @@ pub async fn get_document(
|
|||
pub async fn delete_document(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<(String, String)>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
let index = data.db.open_index(&path.0)
|
||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
||||
let document_id = meilisearch_core::serde::compute_document_id(path.1.clone());
|
||||
|
||||
let mut update_writer = data.db.update_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let mut documents_deletion = index.documents_deletion();
|
||||
documents_deletion.delete_document_by_id(document_id);
|
||||
|
@ -48,7 +49,7 @@ pub async fn delete_document(
|
|||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
update_writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||
}
|
||||
|
@ -67,7 +68,7 @@ pub async fn get_all_documents(
|
|||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
params: web::Query<BrowseQuery>,
|
||||
) -> Result<web::Json<Vec<Document>>> {
|
||||
) -> aweb::Result<web::Json<Vec<Document>>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
@ -76,7 +77,7 @@ pub async fn get_all_documents(
|
|||
let limit = params.limit.unwrap_or(20);
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let documents_ids: Result<BTreeSet<_>, _> = index
|
||||
.documents_fields_counts
|
||||
|
@ -123,19 +124,19 @@ async fn update_multiple_documents(
|
|||
params: web::Query<UpdateDocumentsQuery>,
|
||||
body: web::Json<Vec<Document>>,
|
||||
is_partial: bool
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let mut schema = index
|
||||
.main
|
||||
.schema(&reader)
|
||||
.map_err(|_| ResponseError::Schema)?
|
||||
.ok_or(ResponseError::Schema)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||
.ok_or(ResponseError::Internal("Impossible to retrieve the schema".to_string()))?;
|
||||
|
||||
if schema.primary_key().is_none() {
|
||||
let id = match params.primary_key.clone() {
|
||||
|
@ -143,19 +144,19 @@ async fn update_multiple_documents(
|
|||
None => {
|
||||
body.first()
|
||||
.and_then(|docs| find_primary_key(docs))
|
||||
.ok_or(ResponseError::InferPrimaryKey)?
|
||||
.ok_or(ResponseError::BadRequest("Impossible to infer the primary key".to_string()))?
|
||||
}
|
||||
};
|
||||
|
||||
let mut writer = data.db.main_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
schema.set_primary_key(&id)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
index.main.put_schema(&mut writer, &schema)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
}
|
||||
|
||||
let mut document_addition = if is_partial {
|
||||
|
@ -169,11 +170,11 @@ async fn update_multiple_documents(
|
|||
}
|
||||
|
||||
let mut update_writer = data.db.update_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
let update_id = document_addition.finalize(&mut update_writer)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
update_writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||
}
|
||||
|
@ -184,7 +185,7 @@ pub async fn add_documents(
|
|||
path: web::Path<String>,
|
||||
params: web::Query<UpdateDocumentsQuery>,
|
||||
body: web::Json<Vec<Document>>
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
update_multiple_documents(data, path, params, body, false).await
|
||||
}
|
||||
|
||||
|
@ -194,7 +195,7 @@ pub async fn update_documents(
|
|||
path: web::Path<String>,
|
||||
params: web::Query<UpdateDocumentsQuery>,
|
||||
body: web::Json<Vec<Document>>
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
update_multiple_documents(data, path, params, body, true).await
|
||||
}
|
||||
|
||||
|
@ -203,13 +204,13 @@ pub async fn delete_documents(
|
|||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
body: web::Json<Vec<Value>>
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let mut writer = data.db.update_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let mut documents_deletion = index.documents_deletion();
|
||||
|
||||
|
@ -224,7 +225,7 @@ pub async fn delete_documents(
|
|||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||
}
|
||||
|
@ -233,19 +234,19 @@ pub async fn delete_documents(
|
|||
pub async fn clear_all_documents(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let mut writer = data.db.update_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let update_id = index.clear_all(&mut writer)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::error::ResponseError;
|
||||
use actix_web::*;
|
||||
use actix_web::{web, get, put, HttpResponse};
|
||||
use actix_web as aweb;
|
||||
use crate::Data;
|
||||
use heed::types::{Str, Unit};
|
||||
use serde::Deserialize;
|
||||
|
@ -9,14 +10,14 @@ const UNHEALTHY_KEY: &str = "_is_unhealthy";
|
|||
#[get("/health")]
|
||||
pub async fn get_health(
|
||||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let common_store = data.db.common_store();
|
||||
|
||||
if let Ok(Some(_)) = common_store.get::<_, Str, Unit>(&reader, UNHEALTHY_KEY) {
|
||||
return Err(ResponseError::Maintenance)?;
|
||||
return Err(ResponseError::Maintenance.into());
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
|
@ -24,28 +25,28 @@ pub async fn get_health(
|
|||
|
||||
pub async fn set_healthy(
|
||||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
let mut writer = data.db.main_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
let common_store = data.db.common_store();
|
||||
common_store.delete::<_, Str>(&mut writer, UNHEALTHY_KEY)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub async fn set_unhealthy(
|
||||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
let mut writer = data.db.main_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
let common_store = data.db.common_store();
|
||||
common_store.put::<_, Str, Unit>(&mut writer, UNHEALTHY_KEY, &())
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ pub struct HealtBody {
|
|||
pub async fn change_healthyness(
|
||||
data: web::Data<Data>,
|
||||
body: web::Json<HealtBody>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
if body.health {
|
||||
set_healthy(data).await
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,9 @@ use chrono::{DateTime, Utc};
|
|||
use log::error;
|
||||
use rand::seq::SliceRandom;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use actix_web::*;
|
||||
use actix_web::{web, get, post, delete, HttpResponse};
|
||||
use actix_web as aweb;
|
||||
use meilisearch_core::UpdateStatus;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::Data;
|
||||
|
@ -29,10 +31,10 @@ pub struct IndexResponse {
|
|||
#[get("/indexes")]
|
||||
pub async fn list_indexes(
|
||||
data: web::Data<Data>,
|
||||
) -> Result<web::Json<Vec<IndexResponse>>> {
|
||||
) -> aweb::Result<web::Json<Vec<IndexResponse>>> {
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let mut response_body = Vec::new();
|
||||
|
||||
|
@ -82,13 +84,13 @@ pub async fn list_indexes(
|
|||
pub async fn get_index(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<web::Json<IndexResponse>> {
|
||||
) -> aweb::Result<web::Json<IndexResponse>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let name = index.main.name(&reader)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?
|
||||
|
@ -129,10 +131,10 @@ pub struct IndexCreateRequest {
|
|||
pub async fn create_index(
|
||||
data: web::Data<Data>,
|
||||
body: web::Json<IndexCreateRequest>
|
||||
) -> Result<web::Json<IndexResponse>> {
|
||||
) -> aweb::Result<web::Json<IndexResponse>> {
|
||||
|
||||
if let (None, None) = (body.name.clone(), body.uid.clone()) {
|
||||
return Err(ResponseError::BadRequest("Index creation must have an uid".to_string()))?;
|
||||
return Err(ResponseError::BadRequest("Index creation must have an uid".to_string()).into());
|
||||
}
|
||||
|
||||
let uid = match body.uid.clone() {
|
||||
|
@ -143,7 +145,7 @@ pub async fn create_index(
|
|||
{
|
||||
uid
|
||||
} else {
|
||||
return Err(ResponseError::InvalidIndexUid)?;
|
||||
return Err(ResponseError::InvalidIndexUid.into());
|
||||
}
|
||||
}
|
||||
None => loop {
|
||||
|
@ -158,7 +160,7 @@ pub async fn create_index(
|
|||
.map_err(|e| ResponseError::CreateIndex(e.to_string()))?;
|
||||
|
||||
let mut writer = data.db.main_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let name = body.name.clone().unwrap_or(uid.clone());
|
||||
created_index.main.put_name(&mut writer, &name)
|
||||
|
@ -187,7 +189,7 @@ pub async fn create_index(
|
|||
}
|
||||
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(web::Json(IndexResponse {
|
||||
name,
|
||||
|
@ -220,13 +222,13 @@ pub async fn update_index(
|
|||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
body: web::Json<IndexCreateRequest>
|
||||
) -> Result<web::Json<IndexResponse>> {
|
||||
) -> aweb::Result<web::Json<IndexResponse>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let mut writer = data.db.main_write_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
if let Some(name) = body.name.clone() {
|
||||
index.main.put_name(&mut writer, &name)
|
||||
|
@ -238,7 +240,7 @@ pub async fn update_index(
|
|||
.map_err(|e| ResponseError::Internal(e.to_string()))? {
|
||||
match schema.primary_key() {
|
||||
Some(_) => {
|
||||
return Err(ResponseError::BadRequest("The primary key cannot be updated".to_string()))?;
|
||||
return Err(ResponseError::BadRequest("The primary key cannot be updated".to_string()).into());
|
||||
}
|
||||
None => {
|
||||
schema
|
||||
|
@ -254,10 +256,10 @@ pub async fn update_index(
|
|||
index.main.put_updated_at(&mut writer)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
writer.commit()
|
||||
.map_err(|_| ResponseError::CommitTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let name = index.main.name(&reader)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?
|
||||
|
@ -290,10 +292,50 @@ pub async fn update_index(
|
|||
pub async fn delete_index(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<HttpResponse> {
|
||||
) -> aweb::Result<HttpResponse> {
|
||||
|
||||
data.db.delete_index(&path.to_string())
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
|
||||
HttpResponse::NoContent().await
|
||||
}
|
||||
|
||||
|
||||
#[get("/indexes/{index_uid}/updates/{update_id}")]
|
||||
pub async fn get_update_status(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<(String, u64)>,
|
||||
) -> aweb::Result<web::Json<UpdateStatus>> {
|
||||
|
||||
let index = data.db.open_index(path.0.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
||||
|
||||
let reader = data.db.update_read_txn()
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let status = index.update_status(&reader, path.1)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
|
||||
match status {
|
||||
Some(status) => Ok(web::Json(status)),
|
||||
None => Err(ResponseError::NotFound(format!("Update {} not found", path.1)).into())
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/indexes/{index_uid}/updates")]
|
||||
pub async fn get_all_updates_status(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> aweb::Result<web::Json<Vec<UpdateStatus>>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.update_read_txn()
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let response = index.all_updates_status(&reader)
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(web::Json(response))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::Data;
|
||||
use actix_web::*;
|
||||
use actix_web::{web, get};
|
||||
use serde::Serialize;
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use actix_web::*;
|
||||
use actix_web::{get, HttpResponse};
|
||||
use serde::Serialize;
|
||||
use log::error;
|
||||
use meilisearch_core::ProcessedUpdateResult;
|
||||
|
@ -10,24 +10,21 @@ pub mod health;
|
|||
pub mod index;
|
||||
pub mod key;
|
||||
pub mod search;
|
||||
// pub mod setting;
|
||||
pub mod stats;
|
||||
// pub mod setting;
|
||||
// pub mod stop_words;
|
||||
// pub mod synonym;
|
||||
pub mod update;
|
||||
|
||||
#[derive(Default, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct IndexUpdateResponse {
|
||||
pub update_id: u64,
|
||||
pub see_more: String,
|
||||
}
|
||||
|
||||
impl IndexUpdateResponse {
|
||||
pub fn with_id(update_id: u64) -> Self {
|
||||
Self {
|
||||
update_id,
|
||||
see_more: "https://docs.meilisearch.com/guides/advanced_guides/asynchronous_updates.html".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ use log::warn;
|
|||
use meilisearch_core::Index;
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use actix_web::*;
|
||||
use actix_web::{web, get, post};
|
||||
use actix_web as aweb;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::helpers::meilisearch::{Error, IndexSearchExt, SearchHit, SearchResult};
|
||||
|
@ -32,19 +33,19 @@ pub async fn search_with_url_query(
|
|||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
params: web::Query<SearchQuery>,
|
||||
) -> Result<web::Json<SearchResult>> {
|
||||
) -> aweb::Result<web::Json<SearchResult>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let schema = index
|
||||
.main
|
||||
.schema(&reader)
|
||||
.map_err(|_| ResponseError::Schema)?
|
||||
.ok_or(ResponseError::Schema)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?
|
||||
.ok_or(ResponseError::Internal("Impossible to retrieve the schema".to_string()))?;
|
||||
|
||||
let mut search_builder = index.new_search(params.q.clone());
|
||||
|
||||
|
@ -142,8 +143,8 @@ pub async fn search_with_url_query(
|
|||
|
||||
let response = match search_builder.search(&reader) {
|
||||
Ok(response) => response,
|
||||
Err(Error::Internal(message)) => return Err(ResponseError::Internal(message))?,
|
||||
Err(others) => return Err(ResponseError::BadRequest(others.to_string()))?,
|
||||
Err(Error::Internal(message)) => return Err(ResponseError::Internal(message).into()),
|
||||
Err(others) => return Err(ResponseError::BadRequest(others.to_string()).into()),
|
||||
};
|
||||
|
||||
Ok(web::Json(response))
|
||||
|
@ -179,7 +180,7 @@ pub struct SearchMultiBodyResponse {
|
|||
pub async fn search_multi_index(
|
||||
data: web::Data<Data>,
|
||||
body: web::Json<SearchMultiBody>,
|
||||
) -> Result<web::Json<SearchMultiBodyResponse>> {
|
||||
) -> aweb::Result<web::Json<SearchMultiBodyResponse>> {
|
||||
|
||||
let mut index_list = body.clone().indexes;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use actix_web::*;
|
||||
use actix_web as aweb;
|
||||
use actix_web::{web, get};
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::error;
|
||||
use pretty_bytes::converter::convert;
|
||||
|
@ -23,12 +24,12 @@ pub struct IndexStatsResponse {
|
|||
pub async fn index_stats(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<web::Json<IndexStatsResponse>> {
|
||||
) -> aweb::Result<web::Json<IndexStatsResponse>> {
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let number_of_documents = index.main.number_of_documents(&reader)
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
@ -38,7 +39,7 @@ pub async fn index_stats(
|
|||
.unwrap_or_default();
|
||||
|
||||
let update_reader = data.db.update_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let is_indexing = data
|
||||
.is_indexing(&update_reader, &path)
|
||||
|
@ -63,14 +64,14 @@ pub struct StatsResult {
|
|||
#[get("/stats")]
|
||||
pub async fn get_stats(
|
||||
data: web::Data<Data>,
|
||||
) -> Result<web::Json<StatsResult>> {
|
||||
) -> aweb::Result<web::Json<StatsResult>> {
|
||||
|
||||
let mut index_list = HashMap::new();
|
||||
|
||||
let reader = data.db.main_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
let update_reader = data.db.update_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
let indexes_set = data.db.indexes_uids();
|
||||
for index_uid in indexes_set {
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
use actix_web::*;
|
||||
use meilisearch_core::UpdateStatus;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::Data;
|
||||
|
||||
#[get("/indexes/{index_uid}/updates/{update_id}")]
|
||||
pub async fn get_update_status(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<(String, u64)>,
|
||||
) -> Result<web::Json<UpdateStatus>> {
|
||||
|
||||
let index = data.db.open_index(path.0.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.0.clone()))?;
|
||||
|
||||
let reader = data.db.update_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
|
||||
let status = index.update_status(&reader, path.1)
|
||||
.map_err(|e| ResponseError::Internal(e.to_string()))?;
|
||||
|
||||
match status {
|
||||
Some(status) => Ok(web::Json(status)),
|
||||
None => Err(ResponseError::UpdateNotFound(path.1))?
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/indexes/{index_uid}/updates")]
|
||||
pub async fn get_all_updates_status(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<web::Json<Vec<UpdateStatus>>> {
|
||||
|
||||
let index = data.db.open_index(path.clone())
|
||||
.ok_or(ResponseError::IndexNotFound(path.clone()))?;
|
||||
|
||||
let reader = data.db.update_read_txn()
|
||||
.map_err(|_| ResponseError::CreateTransaction)?;
|
||||
|
||||
let response = index.all_updates_status(&reader)
|
||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||
|
||||
Ok(web::Json(response))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue