From 4bd7e46ba6051295d4faee8bf2cfcf1917d1307a Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Thu, 16 Apr 2020 18:37:54 +0200 Subject: [PATCH] revert get document method --- meilisearch-core/examples/from_file.rs | 2 +- meilisearch-core/src/database.rs | 16 ++++++++-------- meilisearch-core/src/store/mod.rs | 6 +++--- meilisearch-http/src/helpers/meilisearch.rs | 2 +- meilisearch-http/src/routes/document.rs | 12 ++++++------ 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/meilisearch-core/examples/from_file.rs b/meilisearch-core/examples/from_file.rs index 4312cd2af..2a30d1ce4 100644 --- a/meilisearch-core/examples/from_file.rs +++ b/meilisearch-core/examples/from_file.rs @@ -381,7 +381,7 @@ fn search_command(command: SearchCommand, database: Database) -> Result<(), Box< .sort_unstable_by_key(|m| (m.char_index, m.char_length)); let start_retrieve = Instant::now(); - let result = index.document::(&reader, Some(fields.clone()), doc.id); + let result = index.document::(&reader, Some(&fields), doc.id); retrieve_duration += start_retrieve.elapsed(); match result { diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index b2fdfce3a..87fc24c11 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -756,16 +756,16 @@ mod tests { update_reader.abort(); let reader = db.main_read_txn().unwrap(); - let document: Option = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap(); + let document: Option = index.document(&reader, None, DocumentId(25)).unwrap(); assert!(document.is_none()); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(7_900_334_843_754_999_545)) + .document(&reader, None, DocumentId(7_900_334_843_754_999_545)) .unwrap(); assert!(document.is_some()); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(8_367_468_610_878_465_872)) + .document(&reader, None, DocumentId(8_367_468_610_878_465_872)) .unwrap(); assert!(document.is_some()); } @@ -836,16 +836,16 @@ mod tests { update_reader.abort(); let reader = db.main_read_txn().unwrap(); - let document: Option = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap(); + let document: Option = index.document(&reader, None, DocumentId(25)).unwrap(); assert!(document.is_none()); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(7_900_334_843_754_999_545)) + .document(&reader, None, DocumentId(7_900_334_843_754_999_545)) .unwrap(); assert!(document.is_some()); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(8_367_468_610_878_465_872)) + .document(&reader, None, DocumentId(8_367_468_610_878_465_872)) .unwrap(); assert!(document.is_some()); @@ -882,7 +882,7 @@ mod tests { let reader = db.main_read_txn().unwrap(); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(7_900_334_843_754_999_545)) + .document(&reader, None, DocumentId(7_900_334_843_754_999_545)) .unwrap(); let new_doc1 = serde_json::json!({ @@ -893,7 +893,7 @@ mod tests { assert_eq!(document, Some(new_doc1)); let document: Option = index - .document::<_, String>(&reader, None, DocumentId(8_367_468_610_878_465_872)) + .document(&reader, None, DocumentId(8_367_468_610_878_465_872)) .unwrap(); let new_doc2 = serde_json::json!({ diff --git a/meilisearch-core/src/store/mod.rs b/meilisearch-core/src/store/mod.rs index 342f6c266..48bcfcef8 100644 --- a/meilisearch-core/src/store/mod.rs +++ b/meilisearch-core/src/store/mod.rs @@ -214,17 +214,17 @@ pub struct Index { } impl Index { - pub fn document>( + pub fn document( &self, reader: &heed::RoTxn, - attributes: Option>, + attributes: Option<&HashSet<&str>>, document_id: DocumentId, ) -> MResult> { let schema = self.main.schema(reader)?; let schema = schema.ok_or(Error::SchemaMissing)?; let attributes = match attributes { - Some(attributes) => Some(attributes.iter().filter_map(|name| schema.id(name.as_ref())).collect()), + Some(attributes) => Some(attributes.iter().filter_map(|name| schema.id(*name)).collect()), None => None, }; diff --git a/meilisearch-http/src/helpers/meilisearch.rs b/meilisearch-http/src/helpers/meilisearch.rs index d75fdcced..5b0563ae0 100644 --- a/meilisearch-http/src/helpers/meilisearch.rs +++ b/meilisearch-http/src/helpers/meilisearch.rs @@ -257,7 +257,7 @@ impl<'a> SearchBuilder<'a> { for doc in docs { let mut document: IndexMap = self .index - .document(reader, Some(all_attributes.clone()), doc.id) + .document(reader, Some(&all_attributes), doc.id) .map_err(|e| Error::RetrieveDocument(doc.id.0, e.to_string()))? .ok_or(Error::DocumentNotFound(doc.id.0))?; diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index c7dc20bc0..54183108f 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -1,3 +1,4 @@ +use std::collections::HashSet; use std::collections::BTreeSet; use actix_web as aweb; @@ -35,7 +36,7 @@ pub async fn get_document( .map_err(|err| ResponseError::Internal(err.to_string()))?; let response = index - .document::(&reader, None, document_id) + .document::(&reader, None, document_id) .map_err(|_| ResponseError::DocumentNotFound(path.document_id.clone()))? .ok_or(ResponseError::DocumentNotFound(path.document_id.clone()))?; @@ -109,14 +110,13 @@ pub async fn get_all_documents( let documents_ids = documents_ids.map_err(|err| ResponseError::Internal(err.to_string()))?; - let attributes = params - .attributes_to_retrieve - .clone() - .map(|a| a.split(',').map(|a| a.to_string()).collect()); + let attributes: Option> = params + .attributes_to_retrieve.as_ref() + .map(|a| a.split(',').collect()); let mut response = Vec::::new(); for document_id in documents_ids { - if let Ok(Some(document)) = index.document(&reader, attributes.clone(), document_id) { + if let Ok(Some(document)) = index.document(&reader, attributes.as_ref(), document_id) { response.push(document); } }