remove more warnings and fix some tests

This commit is contained in:
Louis Dureuil 2023-10-25 14:49:25 +02:00
parent fa6c7f65ca
commit 290e773d23
No known key found for this signature in database
6 changed files with 19 additions and 59 deletions

View File

@ -1861,8 +1861,7 @@ pub(crate) mod tests {
use big_s::S; use big_s::S;
use maplit::hashset; use maplit::hashset;
let mut index = TempIndex::new(); let index = TempIndex::new();
let index = index;
index index
.update_settings(|settings| { .update_settings(|settings| {
@ -1973,7 +1972,7 @@ pub(crate) mod tests {
use big_s::S; use big_s::S;
use maplit::hashset; use maplit::hashset;
let mut index = TempIndex::new(); let index = TempIndex::new();
index index
.update_settings(|settings| { .update_settings(|settings| {
@ -2561,10 +2560,7 @@ pub(crate) mod tests {
4 2 4 2
"###); "###);
let mut wtxn = index.write_txn().unwrap(); index.delete_documents(Default::default());
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
delete.execute().unwrap();
wtxn.commit().unwrap();
db_snap!(index, documents_ids, @"[0, 2, 3, ]"); db_snap!(index, documents_ids, @"[0, 2, 3, ]");
db_snap!(index, external_documents_ids, @r###" db_snap!(index, external_documents_ids, @r###"

View File

@ -4,9 +4,8 @@ use std::path::Path;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use crate::facet::FacetType;
use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue}; use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue};
use crate::{make_db_snap_from_iter, obkv_to_json, ExternalDocumentsIds, Index}; use crate::{make_db_snap_from_iter, obkv_to_json, Index};
#[track_caller] #[track_caller]
pub fn default_db_snapshot_settings_for_test(name: Option<&str>) -> (insta::Settings, String) { pub fn default_db_snapshot_settings_for_test(name: Option<&str>) -> (insta::Settings, String) {

View File

@ -566,7 +566,7 @@ mod tests {
#[test] #[test]
fn replace_all_identical_soft_deletion_then_hard_deletion() { fn replace_all_identical_soft_deletion_then_hard_deletion() {
let mut index = TempIndex::new_with_map_size(4096 * 1000 * 100); let index = TempIndex::new_with_map_size(4096 * 1000 * 100);
index index
.update_settings(|settings| { .update_settings(|settings| {

View File

@ -696,7 +696,6 @@ mod tests {
use crate::documents::documents_batch_reader_from_objects; use crate::documents::documents_batch_reader_from_objects;
use crate::index::tests::TempIndex; use crate::index::tests::TempIndex;
use crate::search::TermsMatchingStrategy; use crate::search::TermsMatchingStrategy;
use crate::update::DeleteDocuments;
use crate::{db_snap, BEU16}; use crate::{db_snap, BEU16};
#[test] #[test]
@ -1101,17 +1100,15 @@ mod tests {
{ "objectId": 30, "title": "Hamlet", "_geo": { "lat": 12, "lng": 89 } } { "objectId": 30, "title": "Hamlet", "_geo": { "lat": 12, "lng": 89 } }
])) ]))
.unwrap(); .unwrap();
let mut wtxn = index.write_txn().unwrap();
assert_eq!(index.primary_key(&wtxn).unwrap(), Some("objectId"));
// Delete not all of the documents but some of them. // Delete not all of the documents but some of them.
let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); index.delete_document("30");
builder.delete_external_id("30");
builder.execute().unwrap();
let external_documents_ids = index.external_documents_ids(&wtxn).unwrap(); 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()); assert!(external_documents_ids.get("30").is_none());
wtxn.commit().unwrap();
index index
.add_documents(documents!([ .add_documents(documents!([
@ -2493,16 +2490,8 @@ mod tests {
db_snap!(index, word_fid_docids, 2, @"a48d3f88db33f94bc23110a673ea49e4"); db_snap!(index, word_fid_docids, 2, @"a48d3f88db33f94bc23110a673ea49e4");
db_snap!(index, word_position_docids, 2, @"3c9e66c6768ae2cf42b46b2c46e46a83"); db_snap!(index, word_position_docids, 2, @"3c9e66c6768ae2cf42b46b2c46e46a83");
let mut wtxn = index.write_txn().unwrap();
// Delete not all of the documents but some of them. // Delete not all of the documents but some of them.
let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); index.delete_documents(vec!["0".into(), "3".into()]);
builder.delete_external_id("0");
builder.delete_external_id("3");
let result = builder.execute().unwrap();
println!("{result:?}");
wtxn.commit().unwrap();
db_snap!(index, word_fid_docids, 3, @"4c2e2a1832e5802796edc1638136d933"); db_snap!(index, word_fid_docids, 3, @"4c2e2a1832e5802796edc1638136d933");
db_snap!(index, word_position_docids, 3, @"74f556b91d161d997a89468b4da1cb8f"); db_snap!(index, word_position_docids, 3, @"74f556b91d161d997a89468b4da1cb8f");
@ -2557,7 +2546,7 @@ mod tests {
), ),
] ]
*/ */
let mut index = TempIndex::new(); let index = TempIndex::new();
// START OF BATCH // START OF BATCH

View File

@ -142,9 +142,6 @@ pub fn write_into_lmdb_database_without_merging(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::io::Cursor; use std::io::Cursor;
use std::iter::FromIterator;
use roaring::RoaringBitmap;
use crate::db_snap; use crate::db_snap;
use crate::documents::{DocumentsBatchBuilder, DocumentsBatchReader}; use crate::documents::{DocumentsBatchBuilder, DocumentsBatchReader};
@ -335,22 +332,14 @@ mod tests {
db_snap!(index, word_prefix_pair_proximity_docids, "initial"); db_snap!(index, word_prefix_pair_proximity_docids, "initial");
db_snap!(index, prefix_word_pair_proximity_docids, "initial"); db_snap!(index, prefix_word_pair_proximity_docids, "initial");
let mut wtxn = index.write_txn().unwrap(); index.delete_document("9000");
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
delete.delete_documents(&RoaringBitmap::from_iter([50]));
delete.execute().unwrap();
wtxn.commit().unwrap();
db_snap!(index, documents_ids, "first_delete"); db_snap!(index, documents_ids, "first_delete");
db_snap!(index, word_docids, "first_delete"); db_snap!(index, word_docids, "first_delete");
db_snap!(index, word_prefix_pair_proximity_docids, "first_delete"); db_snap!(index, word_prefix_pair_proximity_docids, "first_delete");
db_snap!(index, prefix_word_pair_proximity_docids, "first_delete"); db_snap!(index, prefix_word_pair_proximity_docids, "first_delete");
let mut wtxn = index.write_txn().unwrap(); index.delete_documents((0..50).map(|id| id.to_string()).collect());
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
delete.delete_documents(&RoaringBitmap::from_iter(0..50));
delete.execute().unwrap();
wtxn.commit().unwrap();
db_snap!(index, documents_ids, "second_delete"); db_snap!(index, documents_ids, "second_delete");
db_snap!(index, word_docids, "second_delete"); db_snap!(index, word_docids, "second_delete");
@ -417,23 +406,14 @@ mod tests {
db_snap!(index, word_prefix_pair_proximity_docids, "initial"); db_snap!(index, word_prefix_pair_proximity_docids, "initial");
db_snap!(index, prefix_word_pair_proximity_docids, "initial"); db_snap!(index, prefix_word_pair_proximity_docids, "initial");
let mut wtxn = index.write_txn().unwrap(); index.delete_document("9000");
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
delete.delete_documents(&RoaringBitmap::from_iter([50]));
delete.execute().unwrap();
wtxn.commit().unwrap();
db_snap!(index, documents_ids, "first_delete"); db_snap!(index, documents_ids, "first_delete");
db_snap!(index, word_docids, "first_delete"); db_snap!(index, word_docids, "first_delete");
db_snap!(index, word_prefix_pair_proximity_docids, "first_delete"); db_snap!(index, word_prefix_pair_proximity_docids, "first_delete");
db_snap!(index, prefix_word_pair_proximity_docids, "first_delete"); db_snap!(index, prefix_word_pair_proximity_docids, "first_delete");
let mut wtxn = index.write_txn().unwrap(); index.delete_documents((0..50).map(|id| id.to_string()).collect());
let mut delete = DeleteDocuments::new(&mut wtxn, &index).unwrap();
delete.delete_documents(&RoaringBitmap::from_iter(0..50));
delete.execute().unwrap();
wtxn.commit().unwrap();
db_snap!(index, documents_ids, "second_delete"); db_snap!(index, documents_ids, "second_delete");
db_snap!(index, word_docids, "second_delete"); db_snap!(index, word_docids, "second_delete");

View File

@ -923,7 +923,7 @@ mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::error::Error;
use crate::index::tests::TempIndex; use crate::index::tests::TempIndex;
use crate::update::{ClearDocuments, DeleteDocuments}; use crate::update::ClearDocuments;
use crate::{Criterion, Filter, SearchResult}; use crate::{Criterion, Filter, SearchResult};
#[test] #[test]
@ -1768,13 +1768,9 @@ mod tests {
} }
index.add_documents(documents! { docs }).unwrap(); index.add_documents(documents! { docs }).unwrap();
let mut wtxn = index.write_txn().unwrap(); index.delete_documents((0..5).map(|id| id.to_string()).collect());
let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap();
(0..5).for_each(|id| {
builder.delete_external_id(&id.to_string());
});
builder.execute().unwrap();
let mut wtxn = index.write_txn().unwrap();
index index
.update_settings_using_wtxn(&mut wtxn, |settings| { .update_settings_using_wtxn(&mut wtxn, |settings| {
settings.set_searchable_fields(vec!["id".to_string()]); settings.set_searchable_fields(vec!["id".to_string()]);