From 58690dfb19971fa4d5dc949135e987fc19ea4b63 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 30 Oct 2023 13:34:07 +0100 Subject: [PATCH] Fix tests compilation after changes to ExternalDocumentsIds API --- milli/src/snapshot_tests.rs | 2 +- milli/src/update/clear_documents.rs | 2 +- milli/src/update/index_documents/mod.rs | 26 ++++++++++++++----------- milli/tests/search/mod.rs | 8 +++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/milli/src/snapshot_tests.rs b/milli/src/snapshot_tests.rs index 730d0a5c8..f3f1eb5a5 100644 --- a/milli/src/snapshot_tests.rs +++ b/milli/src/snapshot_tests.rs @@ -332,7 +332,7 @@ pub fn snap_geo_faceted_documents_ids(index: &Index) -> String { } pub fn snap_external_documents_ids(index: &Index) -> String { let rtxn = index.read_txn().unwrap(); - let external_ids = index.external_documents_ids(&rtxn).unwrap().to_hash_map(); + let external_ids = index.external_documents_ids().to_hash_map(&rtxn).unwrap(); // ensure fixed order (not guaranteed by hashmap) let mut external_ids: Vec<(String, u32)> = external_ids.into_iter().collect(); external_ids.sort_by(|(l, _), (r, _)| l.cmp(r)); diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index 7f528e928..265c6f15a 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -122,7 +122,7 @@ mod tests { assert!(index.words_fst(&rtxn).unwrap().is_empty()); assert!(index.words_prefixes_fst(&rtxn).unwrap().is_empty()); - assert!(index.external_documents_ids(&rtxn).unwrap().is_empty()); + assert!(index.external_documents_ids().is_empty(&rtxn).unwrap()); assert!(index.documents_ids(&rtxn).unwrap().is_empty()); assert!(index.field_distribution(&rtxn).unwrap().is_empty()); assert!(index.geo_rtree(&rtxn).unwrap().is_none()); diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 45ceec7b0..3026ce81c 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -1094,8 +1094,8 @@ mod tests { let txn = index.read_txn().unwrap(); assert_eq!(index.primary_key(&txn).unwrap(), Some("objectId")); - let external_documents_ids = index.external_documents_ids(&txn).unwrap(); - assert!(external_documents_ids.get("30").is_none()); + let external_documents_ids = index.external_documents_ids(); + assert!(external_documents_ids.get(&txn, "30").unwrap().is_none()); index .add_documents(documents!([ @@ -1104,8 +1104,8 @@ mod tests { .unwrap(); let wtxn = index.write_txn().unwrap(); - let external_documents_ids = index.external_documents_ids(&wtxn).unwrap(); - assert!(external_documents_ids.get("30").is_some()); + let external_documents_ids = index.external_documents_ids(); + assert!(external_documents_ids.get(&wtxn, "30").unwrap().is_some()); wtxn.commit().unwrap(); index @@ -1399,8 +1399,8 @@ mod tests { index.add_documents(documents!({ "a" : { "b" : { "c" : 1 }}})).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()); + let external_documents_ids = index.external_documents_ids(); + assert!(external_documents_ids.get(&rtxn, "1").unwrap().is_some()); } #[test] @@ -1665,7 +1665,7 @@ mod tests { let wtxn = index.read_txn().unwrap(); - let map = index.external_documents_ids(&wtxn).unwrap().to_hash_map(); + let map = index.external_documents_ids().to_hash_map(&wtxn).unwrap(); let ids = map.values().collect::>(); assert_eq!(ids.len(), map.len()); @@ -2669,10 +2669,10 @@ mod tests { index: &'t TempIndex, external_ids: &[&str], ) -> Vec { - let external_document_ids = index.external_documents_ids(wtxn).unwrap(); + let external_document_ids = index.external_documents_ids(); let ids_to_delete: Vec = external_ids .iter() - .map(|id| external_document_ids.get(id.as_bytes()).unwrap()) + .map(|id| external_document_ids.get(&wtxn, id).unwrap().unwrap()) .collect(); // Delete some documents. @@ -3052,9 +3052,13 @@ mod tests { let rtxn = index.read_txn().unwrap(); // get internal docids from deleted external document ids - let results = index.external_documents_ids(&rtxn).unwrap(); + let results = index.external_documents_ids(); for id in deleted_external_ids { - assert!(results.get(id).is_none(), "The document {} was supposed to be deleted", id); + assert!( + results.get(&rtxn, id).unwrap().is_none(), + "The document {} was supposed to be deleted", + id + ); } drop(rtxn); } diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index 1c68cfff2..9193ab762 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -88,9 +88,11 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index { pub fn internal_to_external_ids(index: &Index, internal_ids: &[DocumentId]) -> Vec { let rtxn = index.read_txn().unwrap(); - let docid_map = index.external_documents_ids(&rtxn).unwrap(); - let docid_map: std::collections::HashMap<_, _> = - EXTERNAL_DOCUMENTS_IDS.iter().map(|id| (docid_map.get(id).unwrap(), id)).collect(); + let docid_map = index.external_documents_ids(); + let docid_map: std::collections::HashMap<_, _> = EXTERNAL_DOCUMENTS_IDS + .iter() + .map(|id| (docid_map.get(&rtxn, id).unwrap().unwrap(), id)) + .collect(); internal_ids.iter().map(|id| docid_map.get(id).unwrap().to_string()).collect() }