mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01: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));
|
.sort_unstable_by_key(|m| (m.char_index, m.char_length));
|
||||||
|
|
||||||
let start_retrieve = Instant::now();
|
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();
|
retrieve_duration += start_retrieve.elapsed();
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
@ -756,16 +756,16 @@ mod tests {
|
|||||||
update_reader.abort();
|
update_reader.abort();
|
||||||
|
|
||||||
let reader = db.main_read_txn().unwrap();
|
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());
|
assert!(document.is_none());
|
||||||
|
|
||||||
let document: Option<IgnoredAny> = index
|
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();
|
.unwrap();
|
||||||
assert!(document.is_some());
|
assert!(document.is_some());
|
||||||
|
|
||||||
let document: Option<IgnoredAny> = index
|
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();
|
.unwrap();
|
||||||
assert!(document.is_some());
|
assert!(document.is_some());
|
||||||
}
|
}
|
||||||
@ -836,16 +836,16 @@ mod tests {
|
|||||||
update_reader.abort();
|
update_reader.abort();
|
||||||
|
|
||||||
let reader = db.main_read_txn().unwrap();
|
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());
|
assert!(document.is_none());
|
||||||
|
|
||||||
let document: Option<IgnoredAny> = index
|
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();
|
.unwrap();
|
||||||
assert!(document.is_some());
|
assert!(document.is_some());
|
||||||
|
|
||||||
let document: Option<IgnoredAny> = index
|
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();
|
.unwrap();
|
||||||
assert!(document.is_some());
|
assert!(document.is_some());
|
||||||
|
|
||||||
@ -882,7 +882,7 @@ mod tests {
|
|||||||
|
|
||||||
let reader = db.main_read_txn().unwrap();
|
let reader = db.main_read_txn().unwrap();
|
||||||
let document: Option<serde_json::Value> = index
|
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();
|
.unwrap();
|
||||||
|
|
||||||
let new_doc1 = serde_json::json!({
|
let new_doc1 = serde_json::json!({
|
||||||
@ -893,7 +893,7 @@ mod tests {
|
|||||||
assert_eq!(document, Some(new_doc1));
|
assert_eq!(document, Some(new_doc1));
|
||||||
|
|
||||||
let document: Option<serde_json::Value> = index
|
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();
|
.unwrap();
|
||||||
|
|
||||||
let new_doc2 = serde_json::json!({
|
let new_doc2 = serde_json::json!({
|
||||||
|
@ -214,17 +214,17 @@ pub struct Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Index {
|
impl Index {
|
||||||
pub fn document<T: de::DeserializeOwned, R: AsRef<str>>(
|
pub fn document<T: de::DeserializeOwned>(
|
||||||
&self,
|
&self,
|
||||||
reader: &heed::RoTxn<MainT>,
|
reader: &heed::RoTxn<MainT>,
|
||||||
attributes: Option<HashSet<R>>,
|
attributes: Option<&HashSet<&str>>,
|
||||||
document_id: DocumentId,
|
document_id: DocumentId,
|
||||||
) -> MResult<Option<T>> {
|
) -> MResult<Option<T>> {
|
||||||
let schema = self.main.schema(reader)?;
|
let schema = self.main.schema(reader)?;
|
||||||
let schema = schema.ok_or(Error::SchemaMissing)?;
|
let schema = schema.ok_or(Error::SchemaMissing)?;
|
||||||
|
|
||||||
let attributes = match attributes {
|
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,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ impl<'a> SearchBuilder<'a> {
|
|||||||
for doc in docs {
|
for doc in docs {
|
||||||
let mut document: IndexMap<String, Value> = self
|
let mut document: IndexMap<String, Value> = self
|
||||||
.index
|
.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()))?
|
.map_err(|e| Error::RetrieveDocument(doc.id.0, e.to_string()))?
|
||||||
.ok_or(Error::DocumentNotFound(doc.id.0))?;
|
.ok_or(Error::DocumentNotFound(doc.id.0))?;
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use actix_web as aweb;
|
use actix_web as aweb;
|
||||||
@ -35,7 +36,7 @@ pub async fn get_document(
|
|||||||
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let response = index
|
let response = index
|
||||||
.document::<Document, String>(&reader, None, document_id)
|
.document::<Document>(&reader, None, document_id)
|
||||||
.map_err(|_| ResponseError::DocumentNotFound(path.document_id.clone()))?
|
.map_err(|_| ResponseError::DocumentNotFound(path.document_id.clone()))?
|
||||||
.ok_or(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 documents_ids = documents_ids.map_err(|err| ResponseError::Internal(err.to_string()))?;
|
||||||
|
|
||||||
let attributes = params
|
let attributes: Option<HashSet<&str>> = params
|
||||||
.attributes_to_retrieve
|
.attributes_to_retrieve.as_ref()
|
||||||
.clone()
|
.map(|a| a.split(',').collect());
|
||||||
.map(|a| a.split(',').map(|a| a.to_string()).collect());
|
|
||||||
|
|
||||||
let mut response = Vec::<Document>::new();
|
let mut response = Vec::<Document>::new();
|
||||||
for document_id in documents_ids {
|
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);
|
response.push(document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user