mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
style fixes
This commit is contained in:
parent
d9e2e1a177
commit
05344043b2
@ -11,13 +11,20 @@ use heed::CompactionOption;
|
||||
use log::{debug, error};
|
||||
use meilisearch_schema::Schema;
|
||||
|
||||
use crate::{store, update, Index, MResult, Error, UpdateReader, UpdateWriter, MainReader, MainWriter};
|
||||
use crate::{store, update, Index, MResult, Error};
|
||||
|
||||
pub type BoxUpdateFn = Box<dyn Fn(&str, update::ProcessedUpdateResult) + Send + Sync + 'static>;
|
||||
|
||||
type ArcSwapFn = arc_swap::ArcSwapOption<BoxUpdateFn>;
|
||||
|
||||
type SerdeDatetime = SerdeBincode<DateTime<Utc>>;
|
||||
|
||||
pub type MainWriter<'a> = heed::RwTxn<'a, MainT>;
|
||||
pub type MainReader = heed::RoTxn<MainT>;
|
||||
|
||||
pub type UpdateWriter<'a> = heed::RwTxn<'a, UpdateT>;
|
||||
pub type UpdateReader = heed::RoTxn<UpdateT>;
|
||||
|
||||
const UNHEALTHY_KEY: &str = "_is_unhealthy";
|
||||
const LAST_UPDATE_KEY: &str = "last-update";
|
||||
|
||||
@ -427,8 +434,7 @@ impl Database {
|
||||
|
||||
pub fn last_update(&self, reader: &heed::RoTxn<MainT>) -> MResult<Option<DateTime<Utc>>> {
|
||||
match self.common_store()
|
||||
.get::<_, Str, SerdeDatetime>(reader, LAST_UPDATE_KEY)?
|
||||
{
|
||||
.get::<_, Str, SerdeDatetime>(reader, LAST_UPDATE_KEY)? {
|
||||
Some(datetime) => Ok(Some(datetime)),
|
||||
None => Ok(None),
|
||||
}
|
||||
@ -492,7 +498,7 @@ impl Database {
|
||||
|
||||
index
|
||||
.main
|
||||
.put_fields_frequency(writer, &frequency)
|
||||
.put_fields_distribution(writer, &frequency)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1223,4 +1229,3 @@ mod tests {
|
||||
assert_matches!(iter.next(), None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ pub mod settings;
|
||||
pub mod store;
|
||||
pub mod update;
|
||||
|
||||
pub use self::database::{BoxUpdateFn, Database, DatabaseOptions, MainT, UpdateT};
|
||||
pub use self::database::{BoxUpdateFn, Database, DatabaseOptions, MainT, UpdateT, MainWriter, MainReader, UpdateWriter, UpdateReader};
|
||||
pub use self::error::{Error, HeedError, FstError, MResult, pest_error, FacetError};
|
||||
pub use self::filters::Filter;
|
||||
pub use self::number::{Number, ParseNumberError};
|
||||
@ -52,12 +52,6 @@ use crate::reordered_attrs::ReorderedAttrs;
|
||||
type FstSetCow<'a> = fst::Set<Cow<'a, [u8]>>;
|
||||
type FstMapCow<'a> = fst::Map<Cow<'a, [u8]>>;
|
||||
|
||||
pub type MainWriter<'a> = heed::RwTxn<'a, MainT>;
|
||||
pub type MainReader = heed::RoTxn<MainT>;
|
||||
|
||||
pub type UpdateWriter<'a> = heed::RwTxn<'a, UpdateT>;
|
||||
pub type UpdateReader = heed::RoTxn<UpdateT>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Document {
|
||||
pub id: DocumentId,
|
||||
|
@ -197,7 +197,7 @@ impl Main {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn synonyms_list(self, reader: &heed::RoTxn<MainT>) -> MResult<Vec<String>> {
|
||||
pub fn synonyms(self, reader: &heed::RoTxn<MainT>) -> MResult<Vec<String>> {
|
||||
let synonyms = self
|
||||
.synonyms_fst(&reader)?
|
||||
.stream()
|
||||
@ -217,7 +217,7 @@ impl Main {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop_words_list(self, reader: &heed::RoTxn<MainT>) -> MResult<Vec<String>> {
|
||||
pub fn stop_words(self, reader: &heed::RoTxn<MainT>) -> MResult<Vec<String>> {
|
||||
let stop_word_list = self
|
||||
.stop_words_fst(reader)?
|
||||
.stream()
|
||||
@ -249,7 +249,7 @@ impl Main {
|
||||
writer: &mut heed::RwTxn<MainT>,
|
||||
fields_frequency: &FreqsMap,
|
||||
) -> MResult<()> {
|
||||
Ok(self.main.put::<_, Str, SerdeFreqsMap>(writer, FIELDS_FREQUENCY_KEY, fields_frequency)?)
|
||||
Ok(self.main.put::<_, Str, SerdeFreqsMap>(writer, FIELDS_DISTRIBUTION_KEY, fields_frequency)?)
|
||||
}
|
||||
|
||||
pub fn fields_distribution(&self, reader: &heed::RoTxn<MainT>) -> MResult<Option<FreqsMap>> {
|
||||
|
@ -27,7 +27,7 @@ impl Synonyms {
|
||||
self.synonyms.clear(writer)
|
||||
}
|
||||
|
||||
pub fn synonyms_fst<'txn>(self, reader: &'txn heed::RoTxn<MainT>, word: &[u8]) -> ZResult<FstSetCow<'txn>> {
|
||||
pub(crate) fn synonyms_fst<'txn>(self, reader: &'txn heed::RoTxn<MainT>, word: &[u8]) -> ZResult<FstSetCow<'txn>> {
|
||||
match self.synonyms.get(reader, word)? {
|
||||
Some(bytes) => Ok(fst::Set::new(bytes).unwrap().map_data(Cow::Borrowed).unwrap()),
|
||||
None => Ok(fst::Set::default().map_data(Cow::Owned).unwrap()),
|
||||
@ -42,4 +42,3 @@ impl Synonyms {
|
||||
Ok(synonyms)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
[package]
|
||||
name = "meilisearch-error"
|
||||
version = "0.10.1"
|
||||
authors = ["mpostma <postma.marin@protonmail.com>"]
|
||||
authors = ["marin <postma.marin@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
actix-http = "1.0.1"
|
||||
|
@ -57,12 +57,11 @@ pub enum Code {
|
||||
MissingPrimaryKey,
|
||||
PrimaryKeyAlreadyPresent,
|
||||
|
||||
// invalid documents FIXME make one error code?
|
||||
MissingDocumentId,
|
||||
MaxFieldsLimitExceeded,
|
||||
MissingDocumentId,
|
||||
|
||||
Filter,
|
||||
Facet,
|
||||
Filter,
|
||||
|
||||
BadParameter,
|
||||
BadRequest,
|
||||
@ -73,9 +72,9 @@ pub enum Code {
|
||||
MissingAuthorizationHeader,
|
||||
MissingHeader,
|
||||
NotFound,
|
||||
PayloadTooLarge,
|
||||
RetrieveDocument,
|
||||
SearchDocuments,
|
||||
PayloadTooLarge,
|
||||
UnsupportedMediaType,
|
||||
Other,
|
||||
}
|
||||
@ -90,8 +89,7 @@ impl Code {
|
||||
// index related errors
|
||||
CreateIndex => ErrCode::invalid("create_index", StatusCode::BAD_REQUEST),
|
||||
IndexAlreadyExists => ErrCode::invalid("existing_index", StatusCode::BAD_REQUEST),
|
||||
IndexNotFound => ErrCode::invalid("index_not_found", StatusCode::NOT_FOUND),
|
||||
InvalidIndexUid => ErrCode::invalid("invalid_index_uid", StatusCode::BAD_REQUEST),
|
||||
IndexNotFound => ErrCode::invalid("index_not_found", StatusCode::NOT_FOUND), InvalidIndexUid => ErrCode::invalid("invalid_index_uid", StatusCode::BAD_REQUEST),
|
||||
OpenIndex => ErrCode::internal("open_index", StatusCode::INTERNAL_SERVER_ERROR),
|
||||
|
||||
// invalid state error
|
||||
@ -101,24 +99,24 @@ impl Code {
|
||||
PrimaryKeyAlreadyPresent => ErrCode::internal("primary_key_already_present", StatusCode::INTERNAL_SERVER_ERROR),
|
||||
|
||||
// invalid document
|
||||
MissingDocumentId => ErrCode::invalid("MissingDocumentId", StatusCode::BAD_REQUEST),
|
||||
MaxFieldsLimitExceeded => ErrCode::invalid("max_field_limit_exceeded", StatusCode::BAD_REQUEST),
|
||||
MissingDocumentId => ErrCode::invalid("missing_document_id", StatusCode::BAD_REQUEST),
|
||||
|
||||
Filter => ErrCode::invalid("fitler", StatusCode::BAD_REQUEST),
|
||||
Facet => ErrCode::invalid("facet", StatusCode::BAD_REQUEST),
|
||||
Facet => ErrCode::invalid("invalid_facet", StatusCode::BAD_REQUEST),
|
||||
Filter => ErrCode::invalid("invalid_filter", StatusCode::BAD_REQUEST),
|
||||
|
||||
BadParameter => ErrCode::invalid("bad_parameter", StatusCode::BAD_REQUEST),
|
||||
BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST),
|
||||
RetrieveDocument => ErrCode::invalid("retrieve_document", StatusCode::BAD_REQUEST),
|
||||
SearchDocuments => ErrCode::invalid("search_document", StatusCode::BAD_REQUEST),
|
||||
DocumentNotFound => ErrCode::invalid("document_not_found", StatusCode::NOT_FOUND),
|
||||
NotFound => ErrCode::invalid("not_found", StatusCode::NOT_FOUND),
|
||||
InvalidToken => ErrCode::authentication("invalid_token", StatusCode::UNAUTHORIZED),
|
||||
MissingHeader => ErrCode::authentication("missing_header", StatusCode::UNAUTHORIZED),
|
||||
MissingAuthorizationHeader => ErrCode::authentication("missing_authorization_header", StatusCode::FORBIDDEN),
|
||||
DocumentNotFound => ErrCode::internal("document_not_found", StatusCode::NOT_FOUND),
|
||||
Internal => ErrCode::internal("internal", StatusCode::INTERNAL_SERVER_ERROR),
|
||||
Maintenance => ErrCode::invalid("maintenance", StatusCode::SERVICE_UNAVAILABLE),
|
||||
InvalidToken => ErrCode::authentication("invalid_token", StatusCode::UNAUTHORIZED),
|
||||
Maintenance => ErrCode::internal("maintenance", StatusCode::SERVICE_UNAVAILABLE),
|
||||
MissingAuthorizationHeader => ErrCode::authentication("missing_authorization_header", StatusCode::FORBIDDEN),
|
||||
MissingHeader => ErrCode::authentication("missing_header", StatusCode::UNAUTHORIZED),
|
||||
NotFound => ErrCode::invalid("not_found", StatusCode::NOT_FOUND),
|
||||
PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::PAYLOAD_TOO_LARGE),
|
||||
RetrieveDocument => ErrCode::internal("retrieve_document", StatusCode::BAD_REQUEST),
|
||||
SearchDocuments => ErrCode::internal("search_error", StatusCode::BAD_REQUEST),
|
||||
UnsupportedMediaType => ErrCode::invalid("unsupported_media_type", StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
||||
_ => ErrCode::invalid("other", StatusCode::BAD_REQUEST),
|
||||
}
|
||||
@ -131,12 +129,12 @@ impl Code {
|
||||
|
||||
/// return error name, used as error code
|
||||
fn name(&self) -> String {
|
||||
self.err_code().err_name.to_string()
|
||||
self.err_code().error_name.to_string()
|
||||
}
|
||||
|
||||
/// return the error type
|
||||
fn r#type(&self) -> String {
|
||||
self.err_code().err_type.to_string()
|
||||
self.err_code().error_type.to_string()
|
||||
}
|
||||
|
||||
/// return the doc url ascociated with the error
|
||||
@ -148,8 +146,8 @@ impl Code {
|
||||
/// Internal structure providing a convenient way to create error codes
|
||||
struct ErrCode {
|
||||
status_code: StatusCode,
|
||||
err_type: ErrorType,
|
||||
err_name: &'static str,
|
||||
error_type: ErrorType,
|
||||
error_name: &'static str,
|
||||
}
|
||||
|
||||
impl ErrCode {
|
||||
@ -157,24 +155,24 @@ impl ErrCode {
|
||||
fn authentication(err_name: &'static str, status_code: StatusCode) -> ErrCode {
|
||||
ErrCode {
|
||||
status_code,
|
||||
err_name,
|
||||
err_type: ErrorType::Authentication,
|
||||
error_name: err_name,
|
||||
error_type: ErrorType::Authentication,
|
||||
}
|
||||
}
|
||||
|
||||
fn internal(err_name: &'static str, status_code: StatusCode) -> ErrCode {
|
||||
ErrCode {
|
||||
status_code,
|
||||
err_name,
|
||||
err_type: ErrorType::InternalError,
|
||||
error_name: err_name,
|
||||
error_type: ErrorType::InternalError,
|
||||
}
|
||||
}
|
||||
|
||||
fn invalid(err_name: &'static str, status_code: StatusCode) -> ErrCode {
|
||||
ErrCode {
|
||||
status_code,
|
||||
err_name,
|
||||
err_type: ErrorType::InvalidRequest,
|
||||
error_name: err_name,
|
||||
error_type: ErrorType::InvalidRequest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,4 +96,3 @@ impl Data {
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
use std::fmt;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
||||
use actix_http::ResponseBuilder;
|
||||
use actix_web as aweb;
|
||||
use actix_web::error::JsonPayloadError;
|
||||
use actix_web::http::StatusCode;
|
||||
use serde_json::json;
|
||||
use actix_web::error::JsonPayloadError;
|
||||
|
||||
use meilisearch_error::{ErrorCode, Code};
|
||||
|
||||
|
@ -7,10 +7,10 @@ use meilisearch_core::update;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::Data;
|
||||
use crate::error::{Error, ResponseError};
|
||||
use crate::helpers::Authentication;
|
||||
use crate::routes::{IndexParam, IndexUpdateResponse};
|
||||
use crate::Data;
|
||||
|
||||
type Document = IndexMap<String, Value>;
|
||||
|
||||
@ -192,7 +192,7 @@ async fn update_multiple_documents(
|
||||
|
||||
let update_id = data
|
||||
.db
|
||||
.update_write::<_, _, ResponseError>(move |writer| {
|
||||
.update_write::<_, _, ResponseError>(|writer| {
|
||||
let update_id = document_addition.finalize(writer)?;
|
||||
Ok(update_id)
|
||||
})?;
|
||||
|
@ -24,6 +24,7 @@ async fn set_healthy(data: web::Data<Data>) -> Result<HttpResponse, ResponseErro
|
||||
data.db.set_healthy(writer)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
@ -32,6 +33,7 @@ async fn set_unhealthy(data: web::Data<Data>) -> Result<HttpResponse, ResponseEr
|
||||
data.db.set_unhealthy(writer)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,11 @@ async fn get_all(
|
||||
|
||||
let stop_words: BTreeSet<String> = index
|
||||
.main
|
||||
.stop_words_list(&reader)?
|
||||
.stop_words(&reader)?
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
let synonyms_list = index.main.synonyms_list(&reader)?;
|
||||
let synonyms_list = index.main.synonyms(&reader)?;
|
||||
|
||||
let mut synonyms = BTreeMap::new();
|
||||
let index_synonyms = &index.synonyms;
|
||||
|
@ -25,7 +25,7 @@ async fn get(
|
||||
.open_index(&path.index_uid)
|
||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
||||
let reader = data.db.main_read_txn()?;
|
||||
let stop_words = index.main.stop_words_list(&reader)?;
|
||||
let stop_words = index.main.stop_words(&reader)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(stop_words))
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ async fn get(
|
||||
|
||||
let reader = data.db.main_read_txn()?;
|
||||
|
||||
let synonyms_list = index.main.synonyms_list(&reader)?;
|
||||
let synonyms_list = index.main.synonyms(&reader)?;
|
||||
|
||||
let mut synonyms = IndexMap::new();
|
||||
let index_synonyms = &index.synonyms;
|
||||
|
Loading…
Reference in New Issue
Block a user