From 3bd15a4195b68d9191110b07c27084fcdcce46d1 Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 22 May 2020 18:04:23 +0200 Subject: [PATCH] fix tests, restore behavior --- meilisearch-core/examples/from_file.rs | 17 ++- meilisearch-core/src/database.rs | 2 +- meilisearch-core/src/error.rs | 2 +- meilisearch-core/src/store/main.rs | 58 +++------ meilisearch-core/src/store/synonyms.rs | 6 +- meilisearch-error/src/lib.rs | 144 +++++++++++++++------ meilisearch-http/src/error.rs | 27 +++- meilisearch-http/src/routes/document.rs | 12 +- meilisearch-http/src/routes/health.rs | 2 +- meilisearch-http/src/routes/search.rs | 2 +- meilisearch-http/src/routes/setting.rs | 46 ++++--- meilisearch-http/src/routes/stop_words.rs | 8 +- meilisearch-http/src/routes/synonym.rs | 14 +- meilisearch-http/tests/documents_delete.rs | 2 +- meilisearch-http/tests/index.rs | 18 ++- meilisearch-schema/src/error.rs | 3 +- 16 files changed, 218 insertions(+), 145 deletions(-) diff --git a/meilisearch-core/examples/from_file.rs b/meilisearch-core/examples/from_file.rs index 821f23fcc..561036c02 100644 --- a/meilisearch-core/examples/from_file.rs +++ b/meilisearch-core/examples/from_file.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; use structopt::StructOpt; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; -use meilisearch_core::{Database, DatabaseOptions, Highlight, ProcessedUpdateResult}; +use meilisearch_core::{Database, DatabaseOptions, Highlight, ProcessedUpdateResult, Error as MError}; use meilisearch_core::settings::Settings; use meilisearch_schema::FieldId; @@ -126,9 +126,10 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box(|writer| { + index.settings_update(writer, settings)?; + Ok(()) + })?; let mut rdr = if command.csv_data_path.as_os_str() == "-" { csv::Reader::from_reader(Box::new(io::stdin()) as Box) @@ -175,10 +176,12 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box(|writer| { + let update_id = additions.finalize(writer)?; + Ok(update_id) + })?; + println!("committing update..."); - let update_id = additions.finalize(&mut update_writer)?; - update_writer.commit().unwrap(); max_update_id = max_update_id.max(update_id); println!("committed update {}", update_id); } diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 7e44c7f7d..27b66cdf3 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -390,7 +390,7 @@ impl Database { f(&reader) } - pub fn update_write_txn(&self) -> MResult> { + pub(crate) fn update_write_txn(&self) -> MResult> { Ok(self.update_env.typed_write_txn::()?) } diff --git a/meilisearch-core/src/error.rs b/meilisearch-core/src/error.rs index e01816423..962468268 100644 --- a/meilisearch-core/src/error.rs +++ b/meilisearch-core/src/error.rs @@ -37,7 +37,7 @@ pub enum Error { impl ErrorCode for Error { fn error_code(&self) -> Code { //TODO populate codes - Code::Other + Code::Internal } } diff --git a/meilisearch-core/src/store/main.rs b/meilisearch-core/src/store/main.rs index 7873b3dba..21b506307 100644 --- a/meilisearch-core/src/store/main.rs +++ b/meilisearch-core/src/store/main.rs @@ -71,43 +71,42 @@ impl Main { Ok(self.main.get::<_, Str, SerdeDatetime>(reader, UPDATED_AT_KEY)?) } -<<<<<<< HEAD - pub fn put_internal_docids(self, writer: &mut heed::RwTxn, ids: &sdset::Set) -> ZResult<()> { - self.main.put::<_, Str, DocumentsIds>(writer, INTERNAL_DOCIDS_KEY, ids) + pub fn put_internal_docids(self, writer: &mut heed::RwTxn, ids: &sdset::Set) -> MResult<()> { + Ok(self.main.put::<_, Str, DocumentsIds>(writer, INTERNAL_DOCIDS_KEY, ids)?) } - pub fn internal_docids<'txn>(self, reader: &'txn heed::RoTxn) -> ZResult>> { + pub fn internal_docids<'txn>(self, reader: &'txn heed::RoTxn) -> MResult>> { match self.main.get::<_, Str, DocumentsIds>(reader, INTERNAL_DOCIDS_KEY)? { Some(ids) => Ok(ids), None => Ok(Cow::default()), } } - pub fn merge_internal_docids(self, writer: &mut heed::RwTxn, new_ids: &sdset::Set) -> ZResult<()> { + pub fn merge_internal_docids(self, writer: &mut heed::RwTxn, new_ids: &sdset::Set) -> MResult<()> { use sdset::SetOperation; // We do an union of the old and new internal ids. let internal_docids = self.internal_docids(writer)?; let internal_docids = sdset::duo::Union::new(&internal_docids, new_ids).into_set_buf(); - self.put_internal_docids(writer, &internal_docids) + Ok(self.put_internal_docids(writer, &internal_docids)?) } - pub fn remove_internal_docids(self, writer: &mut heed::RwTxn, ids: &sdset::Set) -> ZResult<()> { + pub fn remove_internal_docids(self, writer: &mut heed::RwTxn, ids: &sdset::Set) -> MResult<()> { use sdset::SetOperation; // We do a difference of the old and new internal ids. let internal_docids = self.internal_docids(writer)?; let internal_docids = sdset::duo::Difference::new(&internal_docids, ids).into_set_buf(); - self.put_internal_docids(writer, &internal_docids) + Ok(self.put_internal_docids(writer, &internal_docids)?) } - pub fn put_external_docids(self, writer: &mut heed::RwTxn, ids: &fst::Map) -> ZResult<()> + pub fn put_external_docids(self, writer: &mut heed::RwTxn, ids: &fst::Map) -> MResult<()> where A: AsRef<[u8]>, { - self.main.put::<_, Str, ByteSlice>(writer, EXTERNAL_DOCIDS_KEY, ids.as_fst().as_bytes()) + Ok(self.main.put::<_, Str, ByteSlice>(writer, EXTERNAL_DOCIDS_KEY, ids.as_fst().as_bytes())?) } - pub fn merge_external_docids(self, writer: &mut heed::RwTxn, new_docids: &fst::Map) -> ZResult<()> + pub fn merge_external_docids(self, writer: &mut heed::RwTxn, new_docids: &fst::Map) -> MResult<()> where A: AsRef<[u8]>, { use fst::{Streamer, IntoStreamer}; @@ -118,29 +117,14 @@ impl Main { let mut build = fst::MapBuilder::memory(); while let Some((docid, values)) = op.next() { build.insert(docid, values[0].value).unwrap(); -======= - pub fn put_words_fst(self, writer: &mut heed::RwTxn, fst: &fst::Set) -> MResult<()> { - let bytes = fst.as_fst().as_bytes(); - Ok(self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, bytes)?) - } - - pub unsafe fn static_words_fst(self, reader: &heed::RoTxn) -> MResult> { - match self.main.get::<_, Str, ByteSlice>(reader, WORDS_KEY)? { - Some(bytes) => { - let bytes: &'static [u8] = std::mem::transmute(bytes); - let set = fst::Set::from_static_slice(bytes).unwrap(); - Ok(Some(set)) - } - None => Ok(None), ->>>>>>> 5c760d3... refactor errors / isolate core/http errors } drop(op); let external_docids = build.into_map(); - self.put_external_docids(writer, &external_docids) + Ok(self.put_external_docids(writer, &external_docids)?) } - pub fn remove_external_docids(self, writer: &mut heed::RwTxn, ids: &fst::Map) -> ZResult<()> + pub fn remove_external_docids(self, writer: &mut heed::RwTxn, ids: &fst::Map) -> MResult<()> where A: AsRef<[u8]>, { use fst::{Streamer, IntoStreamer}; @@ -158,29 +142,29 @@ impl Main { self.put_external_docids(writer, &external_docids) } - pub fn external_docids(self, reader: &heed::RoTxn) -> ZResult { + pub fn external_docids(self, reader: &heed::RoTxn) -> MResult { match self.main.get::<_, Str, ByteSlice>(reader, EXTERNAL_DOCIDS_KEY)? { Some(bytes) => Ok(fst::Map::new(bytes).unwrap().map_data(Cow::Borrowed).unwrap()), None => Ok(fst::Map::default().map_data(Cow::Owned).unwrap()), } } - pub fn external_to_internal_docid(self, reader: &heed::RoTxn, external_docid: &str) -> ZResult> { + pub fn external_to_internal_docid(self, reader: &heed::RoTxn, external_docid: &str) -> MResult> { let external_ids = self.external_docids(reader)?; Ok(external_ids.get(external_docid).map(|id| DocumentId(id as u32))) } - pub fn put_words_fst>(self, writer: &mut heed::RwTxn, fst: &fst::Set) -> ZResult<()> { - self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, fst.as_fst().as_bytes()) - } - - pub fn words_fst(self, reader: &heed::RoTxn) -> MResult> { + pub fn words_fst(self, reader: &heed::RoTxn) -> MResult { match self.main.get::<_, Str, ByteSlice>(reader, WORDS_KEY)? { Some(bytes) => Ok(fst::Set::new(bytes).unwrap().map_data(Cow::Borrowed).unwrap()), None => Ok(fst::Set::default().map_data(Cow::Owned).unwrap()), } } + pub fn put_words_fst>(self, writer: &mut heed::RwTxn, fst: &fst::Set) -> MResult<()> { + Ok(self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, fst.as_fst().as_bytes())?) + } + pub fn put_schema(self, writer: &mut heed::RwTxn, schema: &Schema) -> MResult<()> { Ok(self.main.put::<_, Str, SerdeBincode>(writer, SCHEMA_KEY, schema)?) } @@ -206,7 +190,7 @@ impl Main { Ok(self.main.put::<_, Str, ByteSlice>(writer, SYNONYMS_KEY, bytes)?) } - pub(crate) fn synonyms_fst(self, reader: &heed::RoTxn) -> MResult> { + pub(crate) fn synonyms_fst(self, reader: &heed::RoTxn) -> MResult { match self.main.get::<_, Str, ByteSlice>(reader, SYNONYMS_KEY)? { Some(bytes) => Ok(fst::Set::new(bytes).unwrap().map_data(Cow::Borrowed).unwrap()), None => Ok(fst::Set::default().map_data(Cow::Owned).unwrap()), @@ -216,7 +200,6 @@ impl Main { pub fn synonyms_list(self, reader: &heed::RoTxn) -> MResult> { let synonyms = self .synonyms_fst(&reader)? - .unwrap_or_default() .stream() .into_strs()?; Ok(synonyms) @@ -237,7 +220,6 @@ impl Main { pub fn stop_words_list(self, reader: &heed::RoTxn) -> MResult> { let stop_word_list = self .stop_words_fst(reader)? - .unwrap_or_default() .stream() .into_strs()?; Ok(stop_word_list) diff --git a/meilisearch-core/src/store/synonyms.rs b/meilisearch-core/src/store/synonyms.rs index cf7cf5811..699667fcd 100644 --- a/meilisearch-core/src/store/synonyms.rs +++ b/meilisearch-core/src/store/synonyms.rs @@ -34,11 +34,11 @@ impl Synonyms { } } - pub fn synonyms(self, reader: &heed::RoTxn, word: &[u8]) -> MResult>> { + pub fn synonyms(self, reader: &heed::RoTxn, word: &[u8]) -> MResult> { let synonyms = self .synonyms_fst(&reader, word)? - .map(|list| list.stream().into_strs()) - .transpose()?; + .stream() + .into_strs()?; Ok(synonyms) } } diff --git a/meilisearch-error/src/lib.rs b/meilisearch-error/src/lib.rs index d82b81b1b..59715ef9a 100644 --- a/meilisearch-error/src/lib.rs +++ b/meilisearch-error/src/lib.rs @@ -12,9 +12,80 @@ enum ErrorCategory { } pub enum Code { + BadParameter, + BadRequest, + CreateIndex, + DocumentNotFound, + IndexNotFound, + Internal, + InvalidIndexUid, + InvalidToken, + Maintenance, + MissingAuthorizationHeader, + MissingHeader, + NotFound, + OpenIndex, + RetrieveDocument, + SearchDocuments, + PayloadTooLarge, + UnsupportedMediaType, Other, } +impl Code { + + /// ascociate a `Code` variant to the actual ErrCode + fn err_code(&self) -> ErrCode { + use Code::*; + + match self { + BadParameter + | BadRequest + | CreateIndex + | InvalidIndexUid + | OpenIndex + | RetrieveDocument + | SearchDocuments => ErrCode::bad_request(false, false, ErrorCategory::None, 0), + DocumentNotFound + | IndexNotFound + | NotFound => ErrCode::not_found(false, false, ErrorCategory::None, 0), + InvalidToken + | MissingHeader => ErrCode::unauthorized(false, false, ErrorCategory::None, 0), + MissingAuthorizationHeader => ErrCode::forbidden(false, false, ErrorCategory::None, 0), + Internal => ErrCode::internal(false, false, ErrorCategory::None, 0), + Maintenance => ErrCode::service_unavailable(false, false, ErrorCategory::None, 0), + PayloadTooLarge => ErrCode::payload_too_large(false, false, ErrorCategory::None, 0), + UnsupportedMediaType => ErrCode::unsupported_media_type(false, false, ErrorCategory::None, 0), + _ => ErrCode::not_found(false, false, ErrorCategory::None, 0), + } + } + + /// return the HTTP status code ascociated with the `Code` + pub fn http(&self) -> StatusCode { + self.err_code().http_code + } + + /// returns internal error code, in the form: + /// `EPFCNN` + /// - E: plain letter "E", to mark an error code, future main introduce W for warning + /// - P: scope of the error, 0 for private, 1 for public. Private are error that make no sense + /// reporting to the user, they are internal errors, and there is nothing the user can do about + /// them. they are nonetheless returned, without a message, for assistance purpose. + /// - F: 0 or 1, report if the error is fatal. + /// - C: error category, number in 0-9, the category of the error. Categories are still to be determined, input is required. + /// - NN: The error number, two digits, within C. + + + pub fn internal(&self) -> String { + let ErrCode { public, fatal, category, code, .. } = self.err_code(); + format!("E{}{}{}{}", + public as u16, + fatal as u16, + category as u16, + code) + } +} + impl fmt::Display for Code { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.internal().fmt(f) @@ -56,6 +127,42 @@ impl ErrCode { ErrCode::new(public, fatal, StatusCode::INTERNAL_SERVER_ERROR, category, code) } + pub fn bad_request( + public: bool, + fatal: bool, + category: ErrorCategory, + code: u16 + ) -> ErrCode { + ErrCode::new(public, fatal, StatusCode::BAD_REQUEST, category, code) + } + + pub fn unsupported_media_type( + public: bool, + fatal: bool, + category: ErrorCategory, + code: u16 + ) -> ErrCode { + ErrCode::new(public, fatal, StatusCode::UNSUPPORTED_MEDIA_TYPE, category, code) + } + + pub fn payload_too_large( + public: bool, + fatal: bool, + category: ErrorCategory, + code: u16 + ) -> ErrCode { + ErrCode::new(public, fatal, StatusCode::PAYLOAD_TOO_LARGE, category, code) + } + + pub fn service_unavailable( + public: bool, + fatal: bool, + category: ErrorCategory, + code: u16 + ) -> ErrCode { + ErrCode::new(public, fatal, StatusCode::SERVICE_UNAVAILABLE, category, code) + } + pub fn forbidden( public: bool, fatal: bool, @@ -83,40 +190,3 @@ impl ErrCode { ErrCode::new(public, fatal, StatusCode::NOT_FOUND, category, code) } } - -impl Code { - - /// ascociate a `Code` variant to the actual ErrCode - fn err_code(&self) -> ErrCode { - use Code::*; - - match self { - Other => ErrCode::not_found(false, false, ErrorCategory::None, 0), - } - } - - /// return the HTTP status code ascociated with the `Code` - pub fn http(&self) -> StatusCode { - self.err_code().http_code - } - - /// returns internal error code, in the form: - /// `EPFCNN` - /// - E: plain letter "E", to mark an error code, future main introduce W for warning - /// - P: scope of the error, 0 for private, 1 for public. Private are error that make no sense - /// reporting to the user, they are internal errors, and there is nothing the user can do about - /// them. they are nonetheless returned, without a message, for assistance purpose. - /// - F: 0 or 1, report if the error is fatal. - /// - C: error category, number in 0-9, the category of the error. Categories are still to be determined, input is required. - /// - NN: The error number, two digits, within C. - - - pub fn internal(&self) -> String { - let ErrCode { public, fatal, category, code, .. } = self.err_code(); - format!("E{}{}{}{}", - public as u16, - fatal as u16, - category as u16, - code) - } -} diff --git a/meilisearch-http/src/error.rs b/meilisearch-http/src/error.rs index b5dde6f6e..14d5f33e8 100644 --- a/meilisearch-http/src/error.rs +++ b/meilisearch-http/src/error.rs @@ -41,7 +41,6 @@ pub enum Error { MissingHeader(String), NotFound(String), OpenIndex(String), - FilterParsing(String), RetrieveDocument(u32, String), SearchDocuments(String), PayloadTooLarge, @@ -52,8 +51,26 @@ impl error::Error for Error {} impl ErrorCode for Error { fn error_code(&self) -> Code { - //TODO populate with right error codes - Code::Other + use Error::*; + match self { + BadParameter(_, _) => Code::BadParameter, + BadRequest(_) => Code::BadRequest, + CreateIndex(_) => Code::CreateIndex, + DocumentNotFound(_) => Code::DocumentNotFound, + IndexNotFound(_) => Code::IndexNotFound, + Internal(_) => Code::Internal, + InvalidIndexUid => Code::InvalidIndexUid, + InvalidToken(_) => Code::InvalidToken, + Maintenance => Code::Maintenance, + MissingAuthorizationHeader => Code::MissingAuthorizationHeader, + MissingHeader(_) => Code::MissingHeader, + NotFound(_) => Code::NotFound, + OpenIndex(_) => Code::OpenIndex, + RetrieveDocument(_, _) => Code::RetrieveDocument, + SearchDocuments(_) => Code::SearchDocuments, + PayloadTooLarge => Code::PayloadTooLarge, + UnsupportedMediaType => Code::UnsupportedMediaType, + } } } @@ -69,7 +86,7 @@ impl error::Error for FacetCountError {} impl ErrorCode for FacetCountError { fn error_code(&self) -> Code { - unimplemented!() + Code::BadRequest } } @@ -152,7 +169,7 @@ impl Error { Error::Maintenance } - pub fn retrieve_document(doc_id: u64, err: impl fmt::Display) -> Error { + pub fn retrieve_document(doc_id: u32, err: impl fmt::Display) -> Error { Error::RetrieveDocument(doc_id, err.to_string()) } diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index 12e4b41f6..c97bc7b28 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -44,10 +44,15 @@ async fn get_document( .ok_or(Error::index_not_found(&path.index_uid))?; let reader = data.db.main_read_txn()?; + let internal_id = index.main .external_to_internal_docid(&reader, &path.document_id)? .ok_or(Error::document_not_found(&path.document_id))?; + let document: Document = index + .document(&reader, None, internal_id)? + .ok_or(Error::document_not_found(&path.document_id))?; + Ok(HttpResponse::Ok().json(document)) } @@ -64,12 +69,13 @@ async fn delete_document( .open_index(&path.index_uid) .ok_or(Error::index_not_found(&path.index_uid))?; - let document_id = meilisearch_core::serde::compute_document_id(&path.document_id); - let mut documents_deletion = index.documents_deletion(); documents_deletion.delete_document_by_external_docid(path.document_id.clone()); - let update_id = data.db.update_write::<_, _, ResponseError>(|writer| Ok(documents_deletion.finalize(writer)?))?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = documents_deletion.finalize(writer)?; + Ok(update_id) + })?; Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id))) } diff --git a/meilisearch-http/src/routes/health.rs b/meilisearch-http/src/routes/health.rs index eb7dfbf74..d0114d8c5 100644 --- a/meilisearch-http/src/routes/health.rs +++ b/meilisearch-http/src/routes/health.rs @@ -43,7 +43,7 @@ struct HealthBody { #[put("/health", wrap = "Authentication::Private")] async fn change_healthyness( data: web::Data, - body: web::Json, + body: web::Json, ) -> Result { if body.health { set_healthy(data).await diff --git a/meilisearch-http/src/routes/search.rs b/meilisearch-http/src/routes/search.rs index b0ee0e6bf..1a2521386 100644 --- a/meilisearch-http/src/routes/search.rs +++ b/meilisearch-http/src/routes/search.rs @@ -99,7 +99,7 @@ async fn search_with_url_query( let field_ids = prepare_facet_list(&facets, &schema, attrs)?; search_builder.add_facets(field_ids); }, - None => todo!() /* return Err(FacetCountError::NoFacetSet.into()) */ + None => return Err(FacetCountError::NoFacetSet.into()), } } diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index 99ea052a9..de4a9fa9e 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -39,12 +39,12 @@ async fn update_all( .open_index(&path.index_uid) .ok_or(Error::index_not_found(&path.index_uid))?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { let settings = body .into_inner() .into_update() .map_err(Error::bad_request)?; - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -74,10 +74,8 @@ async fn get_all( let mut synonyms = BTreeMap::new(); let index_synonyms = &index.synonyms; for synonym in synonyms_list { - let alternative_list = index_synonyms.synonyms(&reader, synonym.as_bytes())?; - if let Some(list) = alternative_list { - synonyms.insert(synonym, list); - } + let list = index_synonyms.synonyms(&reader, synonym.as_bytes())?; + synonyms.insert(synonym, list); } let ranking_rules = index @@ -209,8 +207,8 @@ async fn update_rules( let settings = settings.into_update().map_err(Error::bad_request)?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -235,8 +233,8 @@ async fn delete_rules( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -282,8 +280,8 @@ async fn update_distinct( let settings = settings.into_update().map_err(Error::bad_request)?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -308,8 +306,8 @@ async fn delete_distinct( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -357,8 +355,8 @@ async fn update_searchable( let settings = settings.into_update().map_err(Error::bad_request)?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -383,8 +381,8 @@ async fn delete_searchable( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -434,8 +432,8 @@ async fn update_displayed( let settings = settings.into_update().map_err(Error::bad_request)?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -460,8 +458,8 @@ async fn delete_displayed( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -510,8 +508,8 @@ async fn update_accept_new_fields( let settings = settings.into_update().map_err(Error::bad_request)?; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; diff --git a/meilisearch-http/src/routes/stop_words.rs b/meilisearch-http/src/routes/stop_words.rs index b420c149b..092ca9b2a 100644 --- a/meilisearch-http/src/routes/stop_words.rs +++ b/meilisearch-http/src/routes/stop_words.rs @@ -49,8 +49,8 @@ async fn update( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -75,8 +75,8 @@ async fn delete( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; diff --git a/meilisearch-http/src/routes/synonym.rs b/meilisearch-http/src/routes/synonym.rs index c334297af..0b1867126 100644 --- a/meilisearch-http/src/routes/synonym.rs +++ b/meilisearch-http/src/routes/synonym.rs @@ -34,10 +34,8 @@ async fn get( let mut synonyms = IndexMap::new(); let index_synonyms = &index.synonyms; for synonym in synonyms_list { - let alternative_list = index_synonyms.synonyms(&reader, synonym.as_bytes())?; - if let Some(list) = alternative_list { - synonyms.insert(synonym, list); - } + let list = index_synonyms.synonyms(&reader, synonym.as_bytes())?; + synonyms.insert(synonym, list); } Ok(HttpResponse::Ok().json(synonyms)) @@ -62,8 +60,8 @@ async fn update( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; @@ -88,8 +86,8 @@ async fn delete( ..SettingsUpdate::default() }; - let update_id = data.db.update_write::<_, _, ResponseError>(|mut writer| { - let update_id = index.settings_update(&mut writer, settings)?; + let update_id = data.db.update_write::<_, _, ResponseError>(|writer| { + let update_id = index.settings_update(writer, settings)?; Ok(update_id) })?; diff --git a/meilisearch-http/tests/documents_delete.rs b/meilisearch-http/tests/documents_delete.rs index 48b8f70ee..5aa3e595e 100644 --- a/meilisearch-http/tests/documents_delete.rs +++ b/meilisearch-http/tests/documents_delete.rs @@ -14,7 +14,7 @@ async fn delete() { assert_eq!(status_code, 404); } -// Resolve teh issue https://github.com/meilisearch/MeiliSearch/issues/493 +// Resolve the issue https://github.com/meilisearch/MeiliSearch/issues/493 #[actix_rt::test] async fn delete_batch() { let mut server = common::Server::with_uid("movies"); diff --git a/meilisearch-http/tests/index.rs b/meilisearch-http/tests/index.rs index 6ea81f606..ed67f2d1d 100644 --- a/meilisearch-http/tests/index.rs +++ b/meilisearch-http/tests/index.rs @@ -382,7 +382,7 @@ async fn create_index_failed() { assert_eq!(status_code, 400); let message = res_value["message"].as_str().unwrap(); - assert_eq!(res_value.as_object().unwrap().len(), 1); + assert_eq!(res_value.as_object().unwrap().len(), 4); assert_eq!(message, "Index creation must have an uid"); // 3 - Create a index with extra data @@ -462,7 +462,7 @@ async fn create_index_with_invalid_uid() { assert_eq!(status_code, 400); let message = response["message"].as_str().unwrap(); - assert_eq!(response.as_object().unwrap().len(), 1); + assert_eq!(response.as_object().unwrap().len(), 4); assert_eq!(message, "Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_)."); // 2 - Create the index with invalid uid @@ -475,7 +475,7 @@ async fn create_index_with_invalid_uid() { assert_eq!(status_code, 400); let message = response["message"].as_str().unwrap(); - assert_eq!(response.as_object().unwrap().len(), 1); + assert_eq!(response.as_object().unwrap().len(), 4); assert_eq!(message, "Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_)."); // 3 - Create the index with invalid uid @@ -488,7 +488,7 @@ async fn create_index_with_invalid_uid() { assert_eq!(status_code, 400); let message = response["message"].as_str().unwrap(); - assert_eq!(response.as_object().unwrap().len(), 1); + assert_eq!(response.as_object().unwrap().len(), 4); assert_eq!(message, "Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_)."); // 4 - Create the index with invalid uid @@ -501,7 +501,7 @@ async fn create_index_with_invalid_uid() { assert_eq!(status_code, 400); let message = response["message"].as_str().unwrap(); - assert_eq!(response.as_object().unwrap().len(), 1); + assert_eq!(response.as_object().unwrap().len(), 4); assert_eq!(message, "Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_)."); } @@ -645,12 +645,10 @@ async fn check_add_documents_without_primary_key() { let (response, status_code) = server.add_or_replace_multiple_documents_sync(body).await; - let expected = json!({ - "message": "Could not infer a primary key" - }); - + let message = response["message"].as_str().unwrap(); + assert_eq!(response.as_object().unwrap().len(), 4); + assert_eq!(message, "Could not infer a primary key"); assert_eq!(status_code, 400); - assert_json_eq!(response, expected, ordered: false); } #[actix_rt::test] diff --git a/meilisearch-schema/src/error.rs b/meilisearch-schema/src/error.rs index c1b0ffb3f..84c908596 100644 --- a/meilisearch-schema/src/error.rs +++ b/meilisearch-schema/src/error.rs @@ -26,6 +26,7 @@ impl error::Error for Error {} impl ErrorCode for Error { fn error_code(&self) -> Code { - unimplemented!() + // TODO populate with correct error codes + Code::Internal } }