More tests pass

This commit is contained in:
Louis Dureuil 2024-11-20 11:13:36 +01:00 committed by Clément Renault
parent f893b5153e
commit 61feca1f41
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -2902,17 +2902,14 @@ mod tests {
fn placeholder_search_should_not_return_deleted_documents() { fn placeholder_search_should_not_return_deleted_documents() {
let index = TempIndex::new(); let index = TempIndex::new();
let mut wtxn = index.write_txn().unwrap();
index index
.update_settings_using_wtxn(&mut wtxn, |settings| { .update_settings(|settings| {
settings.set_primary_key(S("docid")); settings.set_primary_key(S("docid"));
}) })
.unwrap(); .unwrap();
index index
.add_documents_using_wtxn( .add_documents(documents!([
&mut wtxn,
documents!([
{ "docid": "1_4", "label": ["sign"] }, { "docid": "1_4", "label": ["sign"] },
{ "docid": "1_5", "label": ["letter"] }, { "docid": "1_5", "label": ["letter"] },
{ "docid": "1_7", "label": ["abstract","cartoon","design","pattern"] }, { "docid": "1_7", "label": ["abstract","cartoon","design","pattern"] },
@ -2936,14 +2933,19 @@ mod tests {
{ "docid": "1_70", "label2": ["geometry", 1.2] }, { "docid": "1_70", "label2": ["geometry", 1.2] },
{ "docid": "1_71", "label2": ["design", 2.2] }, { "docid": "1_71", "label2": ["design", 2.2] },
{ "docid": "1_72", "label2": ["geometry", 1.2] } { "docid": "1_72", "label2": ["geometry", 1.2] }
]), ]))
)
.unwrap(); .unwrap();
let mut wtxn = index.write_txn().unwrap();
let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_4"]); let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_4"]);
wtxn.commit().unwrap();
// Placeholder search // Placeholder search
let results = index.search(&wtxn).execute().unwrap(); let rtxn = index.static_read_txn().unwrap();
let results = index.search(&rtxn).execute().unwrap();
assert!(!results.documents_ids.is_empty()); assert!(!results.documents_ids.is_empty());
for id in results.documents_ids.iter() { for id in results.documents_ids.iter() {
assert!( assert!(
@ -2953,24 +2955,21 @@ mod tests {
); );
} }
wtxn.commit().unwrap(); drop(rtxn);
} }
#[test] #[test]
fn search_should_not_return_deleted_documents() { fn search_should_not_return_deleted_documents() {
let index = TempIndex::new(); let index = TempIndex::new();
let mut wtxn = index.write_txn().unwrap();
index index
.update_settings_using_wtxn(&mut wtxn, |settings| { .update_settings(|settings| {
settings.set_primary_key(S("docid")); settings.set_primary_key(S("docid"));
}) })
.unwrap(); .unwrap();
index index
.add_documents_using_wtxn( .add_documents(documents!([
&mut wtxn,
documents!([
{ "docid": "1_4", "label": ["sign"] }, { "docid": "1_4", "label": ["sign"] },
{ "docid": "1_5", "label": ["letter"] }, { "docid": "1_5", "label": ["letter"] },
{ "docid": "1_7", "label": ["abstract","cartoon","design","pattern"] }, { "docid": "1_7", "label": ["abstract","cartoon","design","pattern"] },
@ -2994,14 +2993,16 @@ mod tests {
{ "docid": "1_70", "label2": ["geometry", 1.2] }, { "docid": "1_70", "label2": ["geometry", 1.2] },
{ "docid": "1_71", "label2": ["design", 2.2] }, { "docid": "1_71", "label2": ["design", 2.2] },
{ "docid": "1_72", "label2": ["geometry", 1.2] } { "docid": "1_72", "label2": ["geometry", 1.2] }
]), ]))
)
.unwrap(); .unwrap();
let mut wtxn = index.write_txn().unwrap();
let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_7", "1_52"]); let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_7", "1_52"]);
wtxn.commit().unwrap();
// search for abstract // search for abstract
let results = index.search(&wtxn).query("abstract").execute().unwrap(); let rtxn = index.read_txn().unwrap();
let results = index.search(&rtxn).query("abstract").execute().unwrap();
assert!(!results.documents_ids.is_empty()); assert!(!results.documents_ids.is_empty());
for id in results.documents_ids.iter() { for id in results.documents_ids.iter() {
assert!( assert!(
@ -3010,8 +3011,6 @@ mod tests {
id id
); );
} }
wtxn.commit().unwrap();
} }
#[test] #[test]