mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
revert get document method
This commit is contained in:
parent
ff3149f6fa
commit
4bd7e46ba6
@ -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::<Document, _>(&reader, Some(fields.clone()), doc.id);
|
||||
let result = index.document::<Document>(&reader, Some(&fields), doc.id);
|
||||
retrieve_duration += start_retrieve.elapsed();
|
||||
|
||||
match result {
|
||||
|
@ -756,16 +756,16 @@ mod tests {
|
||||
update_reader.abort();
|
||||
|
||||
let reader = db.main_read_txn().unwrap();
|
||||
let document: Option<IgnoredAny> = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap();
|
||||
let document: Option<IgnoredAny> = index.document(&reader, None, DocumentId(25)).unwrap();
|
||||
assert!(document.is_none());
|
||||
|
||||
let document: Option<IgnoredAny> = 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<IgnoredAny> = 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<IgnoredAny> = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap();
|
||||
let document: Option<IgnoredAny> = index.document(&reader, None, DocumentId(25)).unwrap();
|
||||
assert!(document.is_none());
|
||||
|
||||
let document: Option<IgnoredAny> = 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<IgnoredAny> = 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<serde_json::Value> = 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<serde_json::Value> = 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!({
|
||||
|
@ -214,17 +214,17 @@ pub struct Index {
|
||||
}
|
||||
|
||||
impl Index {
|
||||
pub fn document<T: de::DeserializeOwned, R: AsRef<str>>(
|
||||
pub fn document<T: de::DeserializeOwned>(
|
||||
&self,
|
||||
reader: &heed::RoTxn<MainT>,
|
||||
attributes: Option<HashSet<R>>,
|
||||
attributes: Option<&HashSet<&str>>,
|
||||
document_id: DocumentId,
|
||||
) -> MResult<Option<T>> {
|
||||
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,
|
||||
};
|
||||
|
||||
|
@ -257,7 +257,7 @@ impl<'a> SearchBuilder<'a> {
|
||||
for doc in docs {
|
||||
let mut document: IndexMap<String, Value> = 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))?;
|
||||
|
||||
|
@ -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::<Document, String>(&reader, None, document_id)
|
||||
.document::<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<HashSet<&str>> = params
|
||||
.attributes_to_retrieve.as_ref()
|
||||
.map(|a| a.split(',').collect());
|
||||
|
||||
let mut response = Vec::<Document>::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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user