fix displayed attributes in document retrieval

This commit is contained in:
mpostma 2021-03-15 10:17:41 +01:00
parent 99c89cf2ba
commit adc71a70ce
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
2 changed files with 69 additions and 74 deletions

78
Cargo.lock generated
View File

@ -160,7 +160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655"
dependencies = [
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -170,7 +170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbcb2b608f0accc2f5bcf3dd872194ce13d94ee45b571487035864cf966b04ef"
dependencies = [
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -365,7 +365,7 @@ checksum = "7f138ac357a674c3b480ddb7bbd894b13c1b6e8927d728bc9ea5e17eee2f8fc9"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -464,7 +464,7 @@ checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -475,7 +475,7 @@ checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -655,9 +655,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byte-unit"
version = "4.0.9"
version = "4.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c8758c32833faaae35b24a73d332e62d0528e89076ae841c63940e37008b153"
checksum = "b9520900471c3a9bbcfe0fd4c7b6bcfeff41b20a76cf91c59b7474b09be1ee27"
dependencies = [
"utf8-width",
]
@ -927,7 +927,7 @@ checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -984,7 +984,7 @@ dependencies = [
"heck",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -1031,7 +1031,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
"synstructure",
]
@ -1172,7 +1172,7 @@ dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -2198,7 +2198,7 @@ dependencies = [
"pest_meta",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -2276,7 +2276,7 @@ checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -2287,7 +2287,7 @@ checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -2329,7 +2329,7 @@ dependencies = [
"proc-macro-error-attr",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
"version_check",
]
@ -2571,14 +2571,13 @@ dependencies = [
[[package]]
name = "regex"
version = "1.4.3"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
@ -2592,9 +2591,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.22"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
[[package]]
name = "remove_dir_all"
@ -2845,7 +2844,7 @@ checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3035,7 +3034,7 @@ dependencies = [
"quote 1.0.9",
"serde",
"serde_derive",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3051,7 +3050,7 @@ dependencies = [
"serde_derive",
"serde_json",
"sha1",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3087,7 +3086,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3103,9 +3102,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717"
checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
@ -3129,7 +3128,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
"unicode-xid 0.2.1",
]
@ -3203,16 +3202,7 @@ checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
]
[[package]]
name = "thread_local"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
dependencies = [
"once_cell",
"syn 1.0.64",
]
[[package]]
@ -3270,7 +3260,7 @@ dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"standback",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3348,7 +3338,7 @@ checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
]
[[package]]
@ -3486,9 +3476,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "typenum"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ucd-trie"
@ -3665,7 +3655,7 @@ dependencies = [
"log",
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
"wasm-bindgen-shared",
]
@ -3699,7 +3689,7 @@ checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.9",
"syn 1.0.63",
"syn 1.0.64",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3860,7 +3850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d498dbd1fd7beb83c86709ae1c33ca50942889473473d287d56ce4770a18edfb"
dependencies = [
"proc-macro2 1.0.24",
"syn 1.0.63",
"syn 1.0.64",
"synstructure",
]

View File

@ -1,15 +1,15 @@
mod search;
mod updates;
use std::sync::Arc;
use std::ops::Deref;
use std::sync::Arc;
use anyhow::{bail, Context};
use serde_json::{Value, Map};
use milli::obkv_to_json;
use serde_json::{Map, Value};
pub use search::{SearchQuery, SearchResult, DEFAULT_SEARCH_LIMIT};
pub use updates::{Settings, Facets, UpdateResult};
pub use updates::{Facets, Settings, UpdateResult};
pub type Document = Map<String, Value>;
@ -76,7 +76,10 @@ impl Index {
.iter()
.filter_map(|f| fields_ids_map.id(f.as_ref()))
.collect::<Vec<_>>(),
None => fields_ids_map.iter().map(|(id, _)| id).collect(),
None => match self.displayed_fields_ids(&txn)? {
Some(fields) => fields,
None => fields_ids_map.iter().map(|(id, _)| id).collect(),
},
};
let iter = self.documents.range(&txn, &(..))?.skip(offset).take(limit);
@ -97,36 +100,38 @@ impl Index {
doc_id: String,
attributes_to_retrieve: Option<Vec<S>>,
) -> anyhow::Result<Map<String, Value>> {
let txn = self.read_txn()?;
let txn = self.read_txn()?;
let fields_ids_map = self.fields_ids_map(&txn)?;
let fields_ids_map = self.fields_ids_map(&txn)?;
let attributes_to_retrieve_ids = match attributes_to_retrieve {
Some(attrs) => attrs
.iter()
.filter_map(|f| fields_ids_map.id(f.as_ref()))
.collect::<Vec<_>>(),
let attributes_to_retrieve_ids = match attributes_to_retrieve {
Some(attrs) => attrs
.iter()
.filter_map(|f| fields_ids_map.id(f.as_ref()))
.collect::<Vec<_>>(),
None => match self.displayed_fields_ids(&txn)? {
Some(fields) => fields,
None => fields_ids_map.iter().map(|(id, _)| id).collect(),
};
},
};
let internal_id = self
.external_documents_ids(&txn)?
.get(doc_id.as_bytes())
.with_context(|| format!("Document with id {} not found", doc_id))?;
let internal_id = self
.external_documents_ids(&txn)?
.get(doc_id.as_bytes())
.with_context(|| format!("Document with id {} not found", doc_id))?;
let document = self
.documents(&txn, std::iter::once(internal_id))?
.into_iter()
.next()
.map(|(_, d)| d);
let document = self
.documents(&txn, std::iter::once(internal_id))?
.into_iter()
.next()
.map(|(_, d)| d);
match document {
Some(document) => Ok(obkv_to_json(
&attributes_to_retrieve_ids,
&fields_ids_map,
document,
)?),
None => bail!("Document with id {} not found", doc_id),
}
match document {
Some(document) => Ok(obkv_to_json(
&attributes_to_retrieve_ids,
&fields_ids_map,
document,
)?),
None => bail!("Document with id {} not found", doc_id),
}
}
}