revert get document method

This commit is contained in:
Quentin de Quelen
2020-04-16 18:37:54 +02:00
committed by qdequele
parent ff3149f6fa
commit 4bd7e46ba6
5 changed files with 19 additions and 19 deletions

View File

@ -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 {

View File

@ -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!({

View File

@ -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,
};