Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Add a test to check that we take care of soft deleted documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Nov 14, 2022
1 parent 4fc6331 commit a636704
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions milli/src/update/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ mod tests {
use super::*;
use crate::error::Error;
use crate::index::tests::TempIndex;
use crate::update::DeleteDocuments;
use crate::{Criterion, Filter, SearchResult};

#[test]
Expand Down Expand Up @@ -1489,4 +1490,34 @@ mod tests {
})
.unwrap();
}

#[test]
fn settings_must_ignore_soft_deleted() {
use serde_json::json;

let index = TempIndex::new();

let mut docs = vec![];
for i in 0..10 {
docs.push(json!({ "id": i, "title": format!("{:x}", i) }));
}
index.add_documents(documents! { docs }).unwrap();

let mut wtxn = index.write_txn().unwrap();
let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap();
(0..5).for_each(|id| drop(builder.delete_external_id(&id.to_string())));
builder.execute().unwrap();

index
.update_settings_using_wtxn(&mut wtxn, |settings| {
settings.set_searchable_fields(vec!["id".to_string()]);
})
.unwrap();
wtxn.commit().unwrap();

let rtxn = index.write_txn().unwrap();
let docs: StdResult<Vec<_>, _> = index.all_documents(&rtxn).unwrap().collect();
let docs = docs.unwrap();
assert_eq!(docs.len(), 5);
}
}

0 comments on commit a636704

Please sign in to comment.