mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
fix tests, restore behavior
This commit is contained in:
parent
c771694623
commit
3bd15a4195
@ -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<dy
|
||||
settings.into_update().unwrap()
|
||||
};
|
||||
|
||||
let mut update_writer = db.update_write_txn().unwrap();
|
||||
index.settings_update(&mut update_writer, settings)?;
|
||||
update_writer.commit().unwrap();
|
||||
db.update_write::<_, _, MError>(|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<dyn Read>)
|
||||
@ -175,10 +176,12 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box<dy
|
||||
|
||||
println!();
|
||||
|
||||
let mut update_writer = db.update_write_txn().unwrap();
|
||||
let update_id = db.update_write::<_, _, MError>(|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);
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ impl Database {
|
||||
f(&reader)
|
||||
}
|
||||
|
||||
pub fn update_write_txn(&self) -> MResult<heed::RwTxn<UpdateT>> {
|
||||
pub(crate) fn update_write_txn(&self) -> MResult<heed::RwTxn<UpdateT>> {
|
||||
Ok(self.update_env.typed_write_txn::<UpdateT>()?)
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub enum Error {
|
||||
impl ErrorCode for Error {
|
||||
fn error_code(&self) -> Code {
|
||||
//TODO populate codes
|
||||
Code::Other
|
||||
Code::Internal
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<MainT>, ids: &sdset::Set<DocumentId>) -> ZResult<()> {
|
||||
self.main.put::<_, Str, DocumentsIds>(writer, INTERNAL_DOCIDS_KEY, ids)
|
||||
pub fn put_internal_docids(self, writer: &mut heed::RwTxn<MainT>, ids: &sdset::Set<DocumentId>) -> MResult<()> {
|
||||
Ok(self.main.put::<_, Str, DocumentsIds>(writer, INTERNAL_DOCIDS_KEY, ids)?)
|
||||
}
|
||||
|
||||
pub fn internal_docids<'txn>(self, reader: &'txn heed::RoTxn<MainT>) -> ZResult<Cow<'txn, sdset::Set<DocumentId>>> {
|
||||
pub fn internal_docids<'txn>(self, reader: &'txn heed::RoTxn<MainT>) -> MResult<Cow<'txn, sdset::Set<DocumentId>>> {
|
||||
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<MainT>, new_ids: &sdset::Set<DocumentId>) -> ZResult<()> {
|
||||
pub fn merge_internal_docids(self, writer: &mut heed::RwTxn<MainT>, new_ids: &sdset::Set<DocumentId>) -> 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<MainT>, ids: &sdset::Set<DocumentId>) -> ZResult<()> {
|
||||
pub fn remove_internal_docids(self, writer: &mut heed::RwTxn<MainT>, ids: &sdset::Set<DocumentId>) -> 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<A>(self, writer: &mut heed::RwTxn<MainT>, ids: &fst::Map<A>) -> ZResult<()>
|
||||
pub fn put_external_docids<A>(self, writer: &mut heed::RwTxn<MainT>, ids: &fst::Map<A>) -> 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<A>(self, writer: &mut heed::RwTxn<MainT>, new_docids: &fst::Map<A>) -> ZResult<()>
|
||||
pub fn merge_external_docids<A>(self, writer: &mut heed::RwTxn<MainT>, new_docids: &fst::Map<A>) -> 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<MainT>, 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<MainT>) -> MResult<Option<fst::Set>> {
|
||||
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<A>(self, writer: &mut heed::RwTxn<MainT>, ids: &fst::Map<A>) -> ZResult<()>
|
||||
pub fn remove_external_docids<A>(self, writer: &mut heed::RwTxn<MainT>, ids: &fst::Map<A>) -> 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<MainT>) -> ZResult<FstMapCow> {
|
||||
pub fn external_docids(self, reader: &heed::RoTxn<MainT>) -> MResult<FstMapCow> {
|
||||
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<MainT>, external_docid: &str) -> ZResult<Option<DocumentId>> {
|
||||
pub fn external_to_internal_docid(self, reader: &heed::RoTxn<MainT>, external_docid: &str) -> MResult<Option<DocumentId>> {
|
||||
let external_ids = self.external_docids(reader)?;
|
||||
Ok(external_ids.get(external_docid).map(|id| DocumentId(id as u32)))
|
||||
}
|
||||
|
||||
pub fn put_words_fst<A: AsRef<[u8]>>(self, writer: &mut heed::RwTxn<MainT>, fst: &fst::Set<A>) -> ZResult<()> {
|
||||
self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, fst.as_fst().as_bytes())
|
||||
}
|
||||
|
||||
pub fn words_fst(self, reader: &heed::RoTxn<MainT>) -> MResult<Option<fst::Set>> {
|
||||
pub fn words_fst(self, reader: &heed::RoTxn<MainT>) -> MResult<FstSetCow> {
|
||||
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<A: AsRef<[u8]>>(self, writer: &mut heed::RwTxn<MainT>, fst: &fst::Set<A>) -> MResult<()> {
|
||||
Ok(self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, fst.as_fst().as_bytes())?)
|
||||
}
|
||||
|
||||
pub fn put_schema(self, writer: &mut heed::RwTxn<MainT>, schema: &Schema) -> MResult<()> {
|
||||
Ok(self.main.put::<_, Str, SerdeBincode<Schema>>(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<MainT>) -> MResult<Option<fst::Set>> {
|
||||
pub(crate) fn synonyms_fst(self, reader: &heed::RoTxn<MainT>) -> MResult<FstSetCow> {
|
||||
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<MainT>) -> MResult<Vec<String>> {
|
||||
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<MainT>) -> MResult<Vec<String>> {
|
||||
let stop_word_list = self
|
||||
.stop_words_fst(reader)?
|
||||
.unwrap_or_default()
|
||||
.stream()
|
||||
.into_strs()?;
|
||||
Ok(stop_word_list)
|
||||
|
@ -34,11 +34,11 @@ impl Synonyms {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn synonyms(self, reader: &heed::RoTxn<MainT>, word: &[u8]) -> MResult<Option<Vec<String>>> {
|
||||
pub fn synonyms(self, reader: &heed::RoTxn<MainT>, word: &[u8]) -> MResult<Vec<String>> {
|
||||
let synonyms = self
|
||||
.synonyms_fst(&reader, word)?
|
||||
.map(|list| list.stream().into_strs())
|
||||
.transpose()?;
|
||||
.stream()
|
||||
.into_strs()?;
|
||||
Ok(synonyms)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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)))
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ struct HealthBody {
|
||||
#[put("/health", wrap = "Authentication::Private")]
|
||||
async fn change_healthyness(
|
||||
data: web::Data<Data>,
|
||||
body: web::Json<HealtBody>,
|
||||
body: web::Json<HealthBody>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
if body.health {
|
||||
set_healthy(data).await
|
||||
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
})?;
|
||||
|
||||
|
@ -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)
|
||||
})?;
|
||||
|
||||
|
@ -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)
|
||||
})?;
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user