mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
Start change http server; finish document endpoint
This commit is contained in:
parent
6cc80d2565
commit
6d6c8e8fb2
10 changed files with 1125 additions and 813 deletions
|
@ -756,16 +756,16 @@ mod tests {
|
|||
update_reader.abort();
|
||||
|
||||
let reader = db.main_read_txn().unwrap();
|
||||
let document: Option<IgnoredAny> = index.document(&reader, None, DocumentId(25)).unwrap();
|
||||
let document: Option<IgnoredAny> = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap();
|
||||
assert!(document.is_none());
|
||||
|
||||
let document: Option<IgnoredAny> = index
|
||||
.document(&reader, None, DocumentId(7_900_334_843_754_999_545))
|
||||
.document::<_, String>(&reader, None, DocumentId(7_900_334_843_754_999_545))
|
||||
.unwrap();
|
||||
assert!(document.is_some());
|
||||
|
||||
let document: Option<IgnoredAny> = index
|
||||
.document(&reader, None, DocumentId(8_367_468_610_878_465_872))
|
||||
.document::<_, String>(&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(&reader, None, DocumentId(25)).unwrap();
|
||||
let document: Option<IgnoredAny> = index.document::<_, String>(&reader, None, DocumentId(25)).unwrap();
|
||||
assert!(document.is_none());
|
||||
|
||||
let document: Option<IgnoredAny> = index
|
||||
.document(&reader, None, DocumentId(7_900_334_843_754_999_545))
|
||||
.document::<_, String>(&reader, None, DocumentId(7_900_334_843_754_999_545))
|
||||
.unwrap();
|
||||
assert!(document.is_some());
|
||||
|
||||
let document: Option<IgnoredAny> = index
|
||||
.document(&reader, None, DocumentId(8_367_468_610_878_465_872))
|
||||
.document::<_, String>(&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(&reader, None, DocumentId(7_900_334_843_754_999_545))
|
||||
.document::<_, String>(&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(&reader, None, DocumentId(8_367_468_610_878_465_872))
|
||||
.document::<_, String>(&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>(
|
||||
pub fn document<T: de::DeserializeOwned, R: AsRef<str>>(
|
||||
&self,
|
||||
reader: &heed::RoTxn<MainT>,
|
||||
attributes: Option<&HashSet<&str>>,
|
||||
attributes: Option<HashSet<R>>,
|
||||
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)).collect()),
|
||||
Some(attributes) => Some(attributes.iter().filter_map(|name| schema.id(name.as_ref())).collect()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue