mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 17:11:15 +08:00
Add some tests to check for the nested documents ids
This commit is contained in:
parent
a892a4a79c
commit
192793ee38
@ -257,12 +257,9 @@ impl fmt::Debug for DocumentId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn contained_in(selector: &str, key: &str) -> bool {
|
fn contained_in(selector: &str, key: &str) -> bool {
|
||||||
selector.starts_with(key)
|
selector.strip_prefix(key).map_or(false, |tail| {
|
||||||
&& selector[key.len()..]
|
tail.chars().next().map(|c| c == PRIMARY_KEY_SPLIT_SYMBOL).unwrap_or(true)
|
||||||
.chars()
|
})
|
||||||
.next()
|
|
||||||
.map(|c| c == PRIMARY_KEY_SPLIT_SYMBOL)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_matching_values(value: Value, selector: &str, output: &mut Vec<Value>) {
|
pub fn fetch_matching_values(value: Value, selector: &str, output: &mut Vec<Value>) {
|
||||||
|
@ -1627,6 +1627,58 @@ mod tests {
|
|||||||
assert_eq!(documents_ids, vec![3]);
|
assert_eq!(documents_ids, vec![3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn retrieve_a_b_nested_document_id() {
|
||||||
|
let path = tempfile::tempdir().unwrap();
|
||||||
|
let mut options = EnvOpenOptions::new();
|
||||||
|
options.map_size(10 * 1024 * 1024); // 10 MB
|
||||||
|
let index = Index::new(options, &path).unwrap();
|
||||||
|
let config = IndexerConfig::default();
|
||||||
|
|
||||||
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
|
let mut builder = update::Settings::new(&mut wtxn, &index, &config);
|
||||||
|
builder.set_primary_key("a.b".to_owned());
|
||||||
|
builder.execute(|_| ()).unwrap();
|
||||||
|
|
||||||
|
let content = documents!({ "a" : { "b" : { "c" : 1 }}});
|
||||||
|
let indexing_config = IndexDocumentsConfig::default();
|
||||||
|
let builder =
|
||||||
|
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||||
|
.unwrap();
|
||||||
|
let (_builder, user_error) = builder.add_documents(content).unwrap();
|
||||||
|
|
||||||
|
// There must be an issue with the primary key no present in the given document
|
||||||
|
user_error.unwrap_err();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn retrieve_a_b_c_nested_document_id() {
|
||||||
|
let path = tempfile::tempdir().unwrap();
|
||||||
|
let mut options = EnvOpenOptions::new();
|
||||||
|
options.map_size(10 * 1024 * 1024); // 10 MB
|
||||||
|
let index = Index::new(options, &path).unwrap();
|
||||||
|
let config = IndexerConfig::default();
|
||||||
|
|
||||||
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
|
let mut builder = update::Settings::new(&mut wtxn, &index, &config);
|
||||||
|
builder.set_primary_key("a.b.c".to_owned());
|
||||||
|
builder.execute(|_| ()).unwrap();
|
||||||
|
|
||||||
|
let content = documents!({ "a" : { "b" : { "c" : 1 }}});
|
||||||
|
let indexing_config = IndexDocumentsConfig::default();
|
||||||
|
let builder =
|
||||||
|
IndexDocuments::new(&mut wtxn, &index, &config, indexing_config.clone(), |_| ())
|
||||||
|
.unwrap();
|
||||||
|
let (builder, user_error) = builder.add_documents(content).unwrap();
|
||||||
|
user_error.unwrap();
|
||||||
|
builder.execute().unwrap();
|
||||||
|
wtxn.commit().unwrap();
|
||||||
|
|
||||||
|
let rtxn = index.read_txn().unwrap();
|
||||||
|
let external_documents_ids = index.external_documents_ids(&rtxn).unwrap();
|
||||||
|
assert!(external_documents_ids.get("1").is_some());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_facets_generation() {
|
fn test_facets_generation() {
|
||||||
let path = tempfile::tempdir().unwrap();
|
let path = tempfile::tempdir().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user