diff --git a/Cargo.lock b/Cargo.lock index f499bf22f..128063cca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2483,6 +2483,7 @@ name = "meilisearch-types" version = "0.29.1" dependencies = [ "actix-web", + "milli 0.33.0", "proptest", "proptest-derive", "serde", diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index d43f864b0..1763119e1 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -13,7 +13,6 @@ pub mod metrics; pub mod route_metrics; use std::sync::{atomic::AtomicBool, Arc}; -use std::time::Duration; use crate::error::MeilisearchHttpError; use actix_web::error::JsonPayloadError; @@ -21,7 +20,6 @@ use actix_web::web::Data; use analytics::Analytics; use error::PayloadError; use http::header::CONTENT_TYPE; -use index_scheduler::milli::update::IndexerConfig; pub use option::Opt; use actix_web::{web, HttpRequest}; @@ -29,7 +27,6 @@ use actix_web::{web, HttpRequest}; use extractors::payload::PayloadConfig; use index_scheduler::IndexScheduler; use meilisearch_auth::AuthController; -use sysinfo::{RefreshKind, System, SystemExt}; pub static AUTOBATCHING_ENABLED: AtomicBool = AtomicBool::new(false); diff --git a/meilisearch-http/src/routes/indexes/mod.rs b/meilisearch-http/src/routes/indexes/mod.rs index 5a303c5e4..f27190b18 100644 --- a/meilisearch-http/src/routes/indexes/mod.rs +++ b/meilisearch-http/src/routes/indexes/mod.rs @@ -1,9 +1,5 @@ -use std::convert::TryFrom; -use std::sync::Arc; - use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; -use index::Index; use index_scheduler::milli::FieldDistribution; use index_scheduler::{IndexScheduler, KindWithContent, Query, Status}; use log::debug; @@ -74,7 +70,6 @@ pub async fn list_indexes( ) -> Result { let search_rules = &index_scheduler.filters().search_rules; let indexes: Vec<_> = index_scheduler.indexes()?; - let nb_indexes = indexes.len(); let indexes = indexes .iter() .filter(|index| search_rules.is_index_authorized(&index.name)) diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 833969384..312742cb7 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -16,7 +16,7 @@ use meilisearch_types::star_or::StarOr; use crate::analytics::Analytics; use crate::extractors::authentication::{policies::*, GuardedData}; -use self::indexes::{IndexStats, IndexView}; +use self::indexes::IndexStats; mod api_key; mod dump; diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 60953512e..cf5ad5ed2 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -6,11 +6,12 @@ edition = "2021" [dependencies] actix-web = { version = "4.2.1", default-features = false } -tokio = "1.0" +milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.33.0" } proptest = { version = "1.0.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" +tokio = "1.0" [features] test-traits = ["proptest", "proptest-derive"] diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 8fe117470..b6383263f 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -351,6 +351,47 @@ impl ErrorCode for JoinError { } } +impl ErrorCode for milli::Error { + fn error_code(&self) -> Code { + use milli::{Error, UserError}; + + match self { + Error::InternalError(_) => Code::Internal, + Error::IoError(_) => Code::Internal, + Error::UserError(ref error) => { + match error { + // TODO: wait for spec for new error codes. + UserError::SerdeJson(_) + | UserError::InvalidLmdbOpenOptions + | UserError::DocumentLimitReached + | UserError::AccessingSoftDeletedDocument { .. } + | UserError::UnknownInternalDocumentId { .. } => Code::Internal, + UserError::InvalidStoreFile => Code::InvalidStore, + UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice, + UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached, + UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded, + UserError::InvalidFilter(_) => Code::Filter, + UserError::MissingDocumentId { .. } => Code::MissingDocumentId, + UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => { + Code::InvalidDocumentId + } + UserError::MissingPrimaryKey => Code::MissingPrimaryKey, + UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent, + UserError::SortRankingRuleMissing => Code::Sort, + UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, + UserError::InvalidSortableAttribute { .. } => Code::Sort, + UserError::CriterionError(_) => Code::InvalidRankingRule, + UserError::InvalidGeoField { .. } => Code::InvalidGeoField, + UserError::SortError(_) => Code::Sort, + UserError::InvalidMinTypoWordLenSetting(_, _) => { + Code::InvalidMinWordLengthForTypo + } + } + } + } + } +} + #[cfg(feature = "test-traits")] mod strategy { use proptest::strategy::Strategy;