Make clippy happy

This commit is contained in:
Clément Renault 2023-01-17 18:01:26 +01:00
parent 2b1f6a7f11
commit 1b78231e18
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
19 changed files with 115 additions and 139 deletions

View File

@ -55,7 +55,7 @@ fn bench_formatting(c: &mut criterion::Criterion) {
group.bench_function(conf.name, |b| { group.bench_function(conf.name, |b| {
b.iter(|| { b.iter(|| {
let mut matcher = conf.matching_words.build(conf.text); let mut matcher = conf.matching_words.build(conf.text);
matcher.format(option.clone()); matcher.format(*option);
}) })
}); });
} }

View File

@ -30,7 +30,7 @@ fn setup_dir(path: impl AsRef<Path>) {
fn setup_index() -> Index { fn setup_index() -> Index {
let path = "benches.mmdb"; let path = "benches.mmdb";
setup_dir(&path); setup_dir(path);
let mut options = EnvOpenOptions::new(); let mut options = EnvOpenOptions::new();
options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.map_size(100 * 1024 * 1024 * 1024); // 100 GB
options.max_readers(10); options.max_readers(10);
@ -62,7 +62,7 @@ fn setup_settings<'t>(
builder.execute(|_| (), || false).unwrap(); builder.execute(|_| (), || false).unwrap();
} }
fn setup_index_with_settings<'t>( fn setup_index_with_settings(
primary_key: &str, primary_key: &str,
searchable_fields: &[&str], searchable_fields: &[&str],
filterable_fields: &[&str], filterable_fields: &[&str],
@ -121,7 +121,7 @@ fn indexing_songs_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -166,7 +166,7 @@ fn reindexing_songs_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -232,7 +232,7 @@ fn deleting_songs_in_batches_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -295,7 +295,7 @@ fn indexing_songs_in_three_batches_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -377,7 +377,7 @@ fn indexing_songs_without_faceted_numbers(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -422,7 +422,7 @@ fn indexing_songs_without_faceted_fields(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -466,7 +466,7 @@ fn indexing_wiki(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -511,7 +511,7 @@ fn reindexing_wiki(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -578,7 +578,7 @@ fn deleting_wiki_in_batches_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -641,7 +641,7 @@ fn indexing_wiki_in_three_batches(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -732,7 +732,7 @@ fn indexing_movies_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -776,7 +776,7 @@ fn reindexing_movies_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -841,7 +841,7 @@ fn deleting_movies_in_batches_default(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -903,7 +903,7 @@ fn indexing_movies_in_three_batches(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1011,7 +1011,7 @@ fn indexing_nested_movies_default(c: &mut Criterion) {
let sortable_fields = ["popularity", "runtime", "vote_average", "release_date"]; let sortable_fields = ["popularity", "runtime", "vote_average", "release_date"];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1078,7 +1078,7 @@ fn deleting_nested_movies_in_batches_default(c: &mut Criterion) {
let sortable_fields = ["popularity", "runtime", "vote_average", "release_date"]; let sortable_fields = ["popularity", "runtime", "vote_average", "release_date"];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1148,7 +1148,7 @@ fn indexing_nested_movies_without_faceted_fields(c: &mut Criterion) {
let sortable_fields = []; let sortable_fields = [];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1192,7 +1192,7 @@ fn indexing_geo(c: &mut Criterion) {
let sortable_fields = ["_geo", "population", "elevation"]; let sortable_fields = ["_geo", "population", "elevation"];
setup_index_with_settings( setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1237,7 +1237,7 @@ fn reindexing_geo(c: &mut Criterion) {
let sortable_fields = ["_geo", "population", "elevation"]; let sortable_fields = ["_geo", "population", "elevation"];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,
@ -1304,7 +1304,7 @@ fn deleting_geo_in_batches_default(c: &mut Criterion) {
let sortable_fields = ["_geo", "population", "elevation"]; let sortable_fields = ["_geo", "population", "elevation"];
let index = setup_index_with_settings( let index = setup_index_with_settings(
&primary_key, primary_key,
&searchable_fields, &searchable_fields,
&filterable_fields, &filterable_fields,
&sortable_fields, &sortable_fields,

View File

@ -56,12 +56,12 @@ impl Conf<'_> {
} }
pub fn base_setup(conf: &Conf) -> Index { pub fn base_setup(conf: &Conf) -> Index {
match remove_dir_all(&conf.database_name) { match remove_dir_all(conf.database_name) {
Ok(_) => (), Ok(_) => (),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => (), Err(e) if e.kind() == std::io::ErrorKind::NotFound => (),
Err(e) => panic!("{}", e), Err(e) => panic!("{}", e),
} }
create_dir_all(&conf.database_name).unwrap(); create_dir_all(conf.database_name).unwrap();
let mut options = EnvOpenOptions::new(); let mut options = EnvOpenOptions::new();
options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.map_size(100 * 1024 * 1024 * 1024); // 100 GB
@ -142,7 +142,7 @@ pub fn run_benches(c: &mut criterion::Criterion, confs: &[Conf]) {
pub fn documents_from(filename: &str, filetype: &str) -> DocumentsBatchReader<impl BufRead + Seek> { pub fn documents_from(filename: &str, filetype: &str) -> DocumentsBatchReader<impl BufRead + Seek> {
let reader = let reader =
File::open(filename).expect(&format!("could not find the dataset in: {}", filename)); File::open(filename).unwrap_or_else(|_| panic!("could not find the dataset in: {}", filename));
let reader = BufReader::new(reader); let reader = BufReader::new(reader);
let documents = match filetype { let documents = match filetype {
"csv" => documents_from_csv(reader).unwrap(), "csv" => documents_from_csv(reader).unwrap(),

View File

@ -398,7 +398,7 @@ pub mod tests {
/// Create a raw [Token]. You must specify the string that appear BEFORE your element followed by your element /// Create a raw [Token]. You must specify the string that appear BEFORE your element followed by your element
pub fn rtok<'a>(before: &'a str, value: &'a str) -> Token<'a> { pub fn rtok<'a>(before: &'a str, value: &'a str) -> Token<'a> {
// if the string is empty we still need to return 1 for the line number // if the string is empty we still need to return 1 for the line number
let lines = before.is_empty().then(|| 1).unwrap_or_else(|| before.lines().count()); let lines = before.is_empty().then_some(1).unwrap_or_else(|| before.lines().count());
let offset = before.chars().count(); let offset = before.chars().count();
// the extra field is not checked in the tests so we can set it to nothing // the extra field is not checked in the tests so we can set it to nothing
unsafe { Span::new_from_raw_offset(offset, lines as u32, value, "") }.into() unsafe { Span::new_from_raw_offset(offset, lines as u32, value, "") }.into()

View File

@ -1297,7 +1297,7 @@ pub(crate) mod tests {
pub fn delete_document(&self, external_document_id: &str) { pub fn delete_document(&self, external_document_id: &str) {
let mut wtxn = self.write_txn().unwrap(); let mut wtxn = self.write_txn().unwrap();
let mut delete = DeleteDocuments::new(&mut wtxn, &self).unwrap(); let mut delete = DeleteDocuments::new(&mut wtxn, self).unwrap();
delete.strategy(self.index_documents_config.deletion_strategy); delete.strategy(self.index_documents_config.deletion_strategy);
delete.delete_external_id(external_document_id); delete.delete_external_id(external_document_id);

View File

@ -964,7 +964,7 @@ pub mod test {
let mut docid_words = HashMap::new(); let mut docid_words = HashMap::new();
for (word, docids) in word_docids.iter() { for (word, docids) in word_docids.iter() {
for docid in docids { for docid in docids {
let words = docid_words.entry(docid).or_insert(vec![]); let words: &mut Vec<_> = docid_words.entry(docid).or_default();
words.push(word.clone()); words.push(word.clone());
} }
} }
@ -996,9 +996,8 @@ pub mod test {
} else { } else {
(s(lword), s(rword), (lposition - rposition + 1) as i32) (s(lword), s(rword), (lposition - rposition + 1) as i32)
}; };
let docids = word_pair_proximity_docids let docids: &mut RoaringBitmap =
.entry(key) word_pair_proximity_docids.entry(key).or_default();
.or_insert(RoaringBitmap::new());
docids.push(candidate); docids.push(candidate);
} }
} }
@ -1015,15 +1014,13 @@ pub mod test {
docid_words.iter().position(|w| w.starts_with(pword)).unwrap(); docid_words.iter().position(|w| w.starts_with(pword)).unwrap();
if lposition < rposition { if lposition < rposition {
let key = (s(lword), s(pword), (rposition - lposition) as i32); let key = (s(lword), s(pword), (rposition - lposition) as i32);
let docids = word_prefix_pair_proximity_docids let docids: &mut RoaringBitmap =
.entry(key) word_prefix_pair_proximity_docids.entry(key).or_default();
.or_insert(RoaringBitmap::new());
docids.push(candidate); docids.push(candidate);
} else { } else {
let key = (s(lword), s(pword), (lposition - rposition) as i32); let key = (s(lword), s(pword), (lposition - rposition) as i32);
let docids = prefix_word_pair_proximity_docids let docids: &mut RoaringBitmap =
.entry(key) prefix_word_pair_proximity_docids.entry(key).or_default();
.or_insert(RoaringBitmap::new());
docids.push(candidate); docids.push(candidate);
}; };
} }

View File

@ -426,7 +426,7 @@ mod test {
let parent = Initial::<NoopDistinct>::new( let parent = Initial::<NoopDistinct>::new(
&context, &context,
query_tree, query_tree,
Some(facet_candidates.clone()), Some(facet_candidates),
false, false,
None, None,
); );
@ -469,7 +469,7 @@ mod test {
let parent = Initial::<NoopDistinct>::new( let parent = Initial::<NoopDistinct>::new(
&context, &context,
Some(query_tree), Some(query_tree),
Some(facet_candidates.clone()), Some(facet_candidates),
false, false,
None, None,
); );

View File

@ -113,7 +113,7 @@ mod test {
let fid = fields_map.id(distinct).unwrap(); let fid = fields_map.id(distinct).unwrap();
let documents = DocumentsBatchReader::from_reader(Cursor::new(JSON.as_slice())).unwrap(); let documents = DocumentsBatchReader::from_reader(Cursor::new(JSON.as_slice())).unwrap();
let map = (0..documents.documents_count() as u32).collect(); let map = (0..documents.documents_count()).collect();
txn.commit().unwrap(); txn.commit().unwrap();

View File

@ -177,11 +177,10 @@ mod tests {
|facet, count, _| { |facet, count, _| {
let facet = OrderedF64Codec::bytes_decode(facet).unwrap(); let facet = OrderedF64Codec::bytes_decode(facet).unwrap();
if nbr_facets == 100 { if nbr_facets == 100 {
return Ok(ControlFlow::Break(())); Ok(ControlFlow::Break(()))
} else { } else {
nbr_facets += 1; nbr_facets += 1;
results.push_str(&format!("{facet}: {count}\n")); results.push_str(&format!("{facet}: {count}\n"));
Ok(ControlFlow::Continue(())) Ok(ControlFlow::Continue(()))
} }
}, },

View File

@ -198,118 +198,94 @@ macro_rules! db_snap {
} }
pub fn snap_word_docids(index: &Index) -> String { pub fn snap_word_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_docids, |(s, b)| { make_db_snap_from_iter!(index, word_docids, |(s, b)| {
&format!("{s:<16} {}", display_bitmap(&b)) &format!("{s:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_exact_word_docids(index: &Index) -> String { pub fn snap_exact_word_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, exact_word_docids, |(s, b)| { make_db_snap_from_iter!(index, exact_word_docids, |(s, b)| {
&format!("{s:<16} {}", display_bitmap(&b)) &format!("{s:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_word_prefix_docids(index: &Index) -> String { pub fn snap_word_prefix_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_prefix_docids, |(s, b)| { make_db_snap_from_iter!(index, word_prefix_docids, |(s, b)| {
&format!("{s:<16} {}", display_bitmap(&b)) &format!("{s:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_exact_word_prefix_docids(index: &Index) -> String { pub fn snap_exact_word_prefix_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, exact_word_prefix_docids, |(s, b)| { make_db_snap_from_iter!(index, exact_word_prefix_docids, |(s, b)| {
&format!("{s:<16} {}", display_bitmap(&b)) &format!("{s:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_docid_word_positions(index: &Index) -> String { pub fn snap_docid_word_positions(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, docid_word_positions, |((idx, s), b)| { make_db_snap_from_iter!(index, docid_word_positions, |((idx, s), b)| {
&format!("{idx:<6} {s:<16} {}", display_bitmap(&b)) &format!("{idx:<6} {s:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_word_pair_proximity_docids(index: &Index) -> String { pub fn snap_word_pair_proximity_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_pair_proximity_docids, |( make_db_snap_from_iter!(index, word_pair_proximity_docids, |((proximity, word1, word2), b)| {
(proximity, word1, word2),
b,
)| {
&format!("{proximity:<2} {word1:<16} {word2:<16} {}", display_bitmap(&b)) &format!("{proximity:<2} {word1:<16} {word2:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_word_prefix_pair_proximity_docids(index: &Index) -> String { pub fn snap_word_prefix_pair_proximity_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_prefix_pair_proximity_docids, |( make_db_snap_from_iter!(index, word_prefix_pair_proximity_docids, |(
(proximity, word1, prefix), (proximity, word1, prefix),
b, b,
)| { )| {
&format!("{proximity:<2} {word1:<16} {prefix:<4} {}", display_bitmap(&b)) &format!("{proximity:<2} {word1:<16} {prefix:<4} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_prefix_word_pair_proximity_docids(index: &Index) -> String { pub fn snap_prefix_word_pair_proximity_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, prefix_word_pair_proximity_docids, |( make_db_snap_from_iter!(index, prefix_word_pair_proximity_docids, |(
(proximity, prefix, word2), (proximity, prefix, word2),
b, b,
)| { )| {
&format!("{proximity:<2} {prefix:<4} {word2:<16} {}", display_bitmap(&b)) &format!("{proximity:<2} {prefix:<4} {word2:<16} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_word_position_docids(index: &Index) -> String { pub fn snap_word_position_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_position_docids, |((word, position), b)| { make_db_snap_from_iter!(index, word_position_docids, |((word, position), b)| {
&format!("{word:<16} {position:<6} {}", display_bitmap(&b)) &format!("{word:<16} {position:<6} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_field_id_word_count_docids(index: &Index) -> String { pub fn snap_field_id_word_count_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, field_id_word_count_docids, |( make_db_snap_from_iter!(index, field_id_word_count_docids, |((field_id, word_count), b)| {
(field_id, word_count),
b,
)| {
&format!("{field_id:<3} {word_count:<6} {}", display_bitmap(&b)) &format!("{field_id:<3} {word_count:<6} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_word_prefix_position_docids(index: &Index) -> String { pub fn snap_word_prefix_position_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, word_prefix_position_docids, |( make_db_snap_from_iter!(index, word_prefix_position_docids, |((word_prefix, position), b)| {
(word_prefix, position),
b,
)| {
&format!("{word_prefix:<4} {position:<6} {}", display_bitmap(&b)) &format!("{word_prefix:<4} {position:<6} {}", display_bitmap(&b))
}); })
snap
} }
pub fn snap_facet_id_f64_docids(index: &Index) -> String { pub fn snap_facet_id_f64_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, facet_id_f64_docids, |( make_db_snap_from_iter!(index, facet_id_f64_docids, |(
FacetGroupKey { field_id, level, left_bound }, FacetGroupKey { field_id, level, left_bound },
FacetGroupValue { size, bitmap }, FacetGroupValue { size, bitmap },
)| { )| {
&format!("{field_id:<3} {level:<2} {left_bound:<6} {size:<2} {}", display_bitmap(&bitmap)) &format!("{field_id:<3} {level:<2} {left_bound:<6} {size:<2} {}", display_bitmap(&bitmap))
}); })
snap
} }
pub fn snap_facet_id_exists_docids(index: &Index) -> String { pub fn snap_facet_id_exists_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, facet_id_exists_docids, |(facet_id, docids)| { make_db_snap_from_iter!(index, facet_id_exists_docids, |(facet_id, docids)| {
&format!("{facet_id:<3} {}", display_bitmap(&docids)) &format!("{facet_id:<3} {}", display_bitmap(&docids))
}); })
snap
} }
pub fn snap_facet_id_string_docids(index: &Index) -> String { pub fn snap_facet_id_string_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, facet_id_string_docids, |( make_db_snap_from_iter!(index, facet_id_string_docids, |(
FacetGroupKey { field_id, level, left_bound }, FacetGroupKey { field_id, level, left_bound },
FacetGroupValue { size, bitmap }, FacetGroupValue { size, bitmap },
)| { )| {
&format!("{field_id:<3} {level:<2} {left_bound:<12} {size:<2} {}", display_bitmap(&bitmap)) &format!("{field_id:<3} {level:<2} {left_bound:<12} {size:<2} {}", display_bitmap(&bitmap))
}); })
snap
} }
pub fn snap_field_id_docid_facet_strings(index: &Index) -> String { pub fn snap_field_id_docid_facet_strings(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, field_id_docid_facet_strings, |( make_db_snap_from_iter!(index, field_id_docid_facet_strings, |(
(field_id, doc_id, string), (field_id, doc_id, string),
other_string, other_string,
)| { )| {
&format!("{field_id:<3} {doc_id:<4} {string:<12} {other_string}") &format!("{field_id:<3} {doc_id:<4} {string:<12} {other_string}")
}); })
snap
} }
pub fn snap_documents_ids(index: &Index) -> String { pub fn snap_documents_ids(index: &Index) -> String {
let rtxn = index.read_txn().unwrap(); let rtxn = index.read_txn().unwrap();
@ -541,7 +517,8 @@ pub fn convert_snap_to_hash_if_needed<'snap>(
snap: &'snap str, snap: &'snap str,
inline: bool, inline: bool,
) -> Vec<(String, Cow<'snap, str>)> { ) -> Vec<(String, Cow<'snap, str>)> {
let store_whole_snapshot = std::env::var("MILLI_TEST_FULL_SNAPS").unwrap_or("false".to_owned()); let store_whole_snapshot =
std::env::var("MILLI_TEST_FULL_SNAPS").unwrap_or_else(|_| "false".to_owned());
let store_whole_snapshot: bool = store_whole_snapshot.parse().unwrap(); let store_whole_snapshot: bool = store_whole_snapshot.parse().unwrap();
let max_len = if inline { 256 } else { 2048 }; let max_len = if inline { 256 } else { 2048 };

View File

@ -659,7 +659,9 @@ mod tests {
// Delete some documents. // Delete some documents.
let mut builder = DeleteDocuments::new(wtxn, index).unwrap(); let mut builder = DeleteDocuments::new(wtxn, index).unwrap();
builder.strategy(strategy); builder.strategy(strategy);
external_ids.iter().for_each(|id| drop(builder.delete_external_id(id))); external_ids.iter().for_each(|id| {
builder.delete_external_id(id);
});
builder.execute().unwrap(); builder.execute().unwrap();
ids_to_delete ids_to_delete

View File

@ -882,6 +882,7 @@ mod tests {
} }
#[test] #[test]
#[allow(clippy::needless_range_loop)]
fn delete_shuffled() { fn delete_shuffled() {
let index = FacetIndex::<OrderedF64Codec>::new(4, 8, 5); let index = FacetIndex::<OrderedF64Codec>::new(4, 8, 5);
let mut txn = index.env.write_txn().unwrap(); let mut txn = index.env.write_txn().unwrap();

View File

@ -254,7 +254,7 @@ pub(crate) mod test_helpers {
max_group_size: u8, max_group_size: u8,
min_level_size: u8, min_level_size: u8,
) -> FacetIndex<BoundCodec> { ) -> FacetIndex<BoundCodec> {
let group_size = std::cmp::min(127, std::cmp::max(group_size, 2)); // 2 <= x <= 127 let group_size = group_size.clamp(2, 127);
let max_group_size = std::cmp::min(127, std::cmp::max(group_size * 2, max_group_size)); // 2*group_size <= x <= 127 let max_group_size = std::cmp::min(127, std::cmp::max(group_size * 2, max_group_size)); // 2*group_size <= x <= 127
let min_level_size = std::cmp::max(1, min_level_size); // 1 <= x <= inf let min_level_size = std::cmp::max(1, min_level_size); // 1 <= x <= inf
let mut options = heed::EnvOpenOptions::new(); let mut options = heed::EnvOpenOptions::new();
@ -307,7 +307,7 @@ pub(crate) mod test_helpers {
min_level_size: self.min_level_size.get(), min_level_size: self.min_level_size.get(),
max_group_size: self.max_group_size.get(), max_group_size: self.max_group_size.get(),
}; };
let key_bytes = BoundCodec::bytes_encode(&key).unwrap(); let key_bytes = BoundCodec::bytes_encode(key).unwrap();
update.insert(wtxn, field_id, &key_bytes, docids).unwrap(); update.insert(wtxn, field_id, &key_bytes, docids).unwrap();
} }
pub fn delete_single_docid<'a>( pub fn delete_single_docid<'a>(
@ -333,7 +333,7 @@ pub(crate) mod test_helpers {
min_level_size: self.min_level_size.get(), min_level_size: self.min_level_size.get(),
max_group_size: self.max_group_size.get(), max_group_size: self.max_group_size.get(),
}; };
let key_bytes = BoundCodec::bytes_encode(&key).unwrap(); let key_bytes = BoundCodec::bytes_encode(key).unwrap();
update.delete(wtxn, field_id, &key_bytes, docids).unwrap(); update.delete(wtxn, field_id, &key_bytes, docids).unwrap();
} }
@ -354,7 +354,7 @@ pub(crate) mod test_helpers {
let key: FacetGroupKey<&[u8]> = let key: FacetGroupKey<&[u8]> =
FacetGroupKey { field_id: *field_id, level: 0, left_bound: &left_bound_bytes }; FacetGroupKey { field_id: *field_id, level: 0, left_bound: &left_bound_bytes };
let key = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_encode(&key).unwrap(); let key = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_encode(&key).unwrap();
let value = CboRoaringBitmapCodec::bytes_encode(&docids).unwrap(); let value = CboRoaringBitmapCodec::bytes_encode(docids).unwrap();
writer.insert(&key, &value).unwrap(); writer.insert(&key, &value).unwrap();
} }
writer.finish().unwrap(); writer.finish().unwrap();
@ -381,19 +381,19 @@ pub(crate) mod test_helpers {
level_no_prefix.extend_from_slice(&field_id.to_be_bytes()); level_no_prefix.extend_from_slice(&field_id.to_be_bytes());
level_no_prefix.push(level_no); level_no_prefix.push(level_no);
let mut iter = self let iter = self
.content .content
.as_polymorph() .as_polymorph()
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(txn, &level_no_prefix) .prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(txn, &level_no_prefix)
.unwrap(); .unwrap();
while let Some(el) = iter.next() { for el in iter {
let (key, value) = el.unwrap(); let (key, value) = el.unwrap();
let key = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key).unwrap(); let key = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key).unwrap();
let mut prefix_start_below = vec![]; let mut prefix_start_below = vec![];
prefix_start_below.extend_from_slice(&field_id.to_be_bytes()); prefix_start_below.extend_from_slice(&field_id.to_be_bytes());
prefix_start_below.push(level_no - 1); prefix_start_below.push(level_no - 1);
prefix_start_below.extend_from_slice(&key.left_bound); prefix_start_below.extend_from_slice(key.left_bound);
let start_below = { let start_below = {
let mut start_below_iter = self let mut start_below_iter = self
@ -405,19 +405,19 @@ pub(crate) mod test_helpers {
) )
.unwrap(); .unwrap();
let (key_bytes, _) = start_below_iter.next().unwrap().unwrap(); let (key_bytes, _) = start_below_iter.next().unwrap().unwrap();
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key_bytes).unwrap() FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes).unwrap()
}; };
assert!(value.size > 0); assert!(value.size > 0);
let mut actual_size = 0; let mut actual_size = 0;
let mut values_below = RoaringBitmap::new(); let mut values_below = RoaringBitmap::new();
let mut iter_below = self let iter_below = self
.content .content
.range(txn, &(start_below..)) .range(txn, &(start_below..))
.unwrap() .unwrap()
.take(value.size as usize); .take(value.size as usize);
while let Some(el) = iter_below.next() { for el in iter_below {
let (_, value) = el.unwrap(); let (_, value) = el.unwrap();
actual_size += 1; actual_size += 1;
values_below |= value.bitmap; values_below |= value.bitmap;
@ -438,8 +438,8 @@ pub(crate) mod test_helpers {
{ {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let txn = self.env.read_txn().unwrap(); let txn = self.env.read_txn().unwrap();
let mut iter = self.content.iter(&txn).unwrap(); let iter = self.content.iter(&txn).unwrap();
while let Some(el) = iter.next() { for el in iter {
let (key, value) = el.unwrap(); let (key, value) = el.unwrap();
let FacetGroupKey { field_id, level, left_bound: bound } = key; let FacetGroupKey { field_id, level, left_bound: bound } = key;
let bound = BoundCodec::bytes_decode(bound).unwrap(); let bound = BoundCodec::bytes_decode(bound).unwrap();

View File

@ -1126,14 +1126,14 @@ mod tests {
})) }))
.unwrap(); .unwrap();
let mut rtxn = index.read_txn().unwrap(); let rtxn = index.read_txn().unwrap();
assert!(index.word_docids.get(&mut rtxn, "0").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "0").unwrap().is_some());
assert!(index.word_docids.get(&mut rtxn, "64").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "64").unwrap().is_some());
assert!(index.word_docids.get(&mut rtxn, "256").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "256").unwrap().is_some());
assert!(index.word_docids.get(&mut rtxn, "1024").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "1024").unwrap().is_some());
assert!(index.word_docids.get(&mut rtxn, "32768").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "32768").unwrap().is_some());
assert!(index.word_docids.get(&mut rtxn, "65535").unwrap().is_some()); assert!(index.word_docids.get(&rtxn, "65535").unwrap().is_some());
} }
#[test] #[test]

View File

@ -1539,7 +1539,9 @@ mod tests {
let mut wtxn = index.write_txn().unwrap(); let mut wtxn = index.write_txn().unwrap();
let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap();
(0..5).for_each(|id| drop(builder.delete_external_id(&id.to_string()))); (0..5).for_each(|id| {
builder.delete_external_id(&id.to_string());
});
builder.execute().unwrap(); builder.execute().unwrap();
index index

View File

@ -87,8 +87,8 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
} }
pub fn internal_to_external_ids(index: &Index, internal_ids: &[DocumentId]) -> Vec<String> { pub fn internal_to_external_ids(index: &Index, internal_ids: &[DocumentId]) -> Vec<String> {
let mut rtxn = index.read_txn().unwrap(); let rtxn = index.read_txn().unwrap();
let docid_map = index.external_documents_ids(&mut rtxn).unwrap(); let docid_map = index.external_documents_ids(&rtxn).unwrap();
let docid_map: std::collections::HashMap<_, _> = let docid_map: std::collections::HashMap<_, _> =
EXTERNAL_DOCUMENTS_IDS.iter().map(|id| (docid_map.get(id).unwrap(), id)).collect(); EXTERNAL_DOCUMENTS_IDS.iter().map(|id| (docid_map.get(id).unwrap(), id)).collect();
internal_ids.iter().map(|id| docid_map.get(id).unwrap().to_string()).collect() internal_ids.iter().map(|id| docid_map.get(id).unwrap().to_string()).collect()
@ -170,18 +170,16 @@ pub fn expected_order(
fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> { fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> {
let mut id = None; let mut id = None;
if let Some((field, filter)) = filter.split_once("!=") { if let Some((field, filter)) = filter.split_once("!=") {
if field == "tag" && document.tag != filter { if field == "tag" && document.tag != filter
id = Some(document.id.clone()) || (field == "asc_desc_rank"
} else if field == "asc_desc_rank" && Ok(&document.asc_desc_rank) != filter.parse::<u32>().as_ref())
&& Ok(&document.asc_desc_rank) != filter.parse::<u32>().as_ref()
{ {
id = Some(document.id.clone()) id = Some(document.id.clone())
} }
} else if let Some((field, filter)) = filter.split_once('=') { } else if let Some((field, filter)) = filter.split_once('=') {
if field == "tag" && document.tag == filter { if field == "tag" && document.tag == filter
id = Some(document.id.clone()) || (field == "asc_desc_rank"
} else if field == "asc_desc_rank" && document.asc_desc_rank == filter.parse::<u32>().unwrap())
&& document.asc_desc_rank == filter.parse::<u32>().unwrap()
{ {
id = Some(document.id.clone()) id = Some(document.id.clone())
} }

View File

@ -7,15 +7,15 @@ fn set_stop_words(index: &Index, stop_words: &[&str]) {
let mut wtxn = index.write_txn().unwrap(); let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default(); let config = IndexerConfig::default();
let mut builder = Settings::new(&mut wtxn, &index, &config); let mut builder = Settings::new(&mut wtxn, index, &config);
let stop_words = stop_words.into_iter().map(|s| s.to_string()).collect(); let stop_words = stop_words.iter().map(|s| s.to_string()).collect();
builder.set_stop_words(stop_words); builder.set_stop_words(stop_words);
builder.execute(|_| (), || false).unwrap(); builder.execute(|_| (), || false).unwrap();
wtxn.commit().unwrap(); wtxn.commit().unwrap();
} }
fn test_phrase_search_with_stop_words_given_criteria(criteria: &[Criterion]) { fn test_phrase_search_with_stop_words_given_criteria(criteria: &[Criterion]) {
let index = super::setup_search_index_with_criteria(&criteria); let index = super::setup_search_index_with_criteria(criteria);
// Add stop_words // Add stop_words
set_stop_words(&index, &["a", "an", "the", "of"]); set_stop_words(&index, &["a", "an", "the", "of"]);

View File

@ -348,9 +348,9 @@ fn criteria_mixup() {
builder.execute(|_| (), || false).unwrap(); builder.execute(|_| (), || false).unwrap();
wtxn.commit().unwrap(); wtxn.commit().unwrap();
let mut rtxn = index.read_txn().unwrap(); let rtxn = index.read_txn().unwrap();
let mut search = Search::new(&mut rtxn, &index); let mut search = Search::new(&rtxn, &index);
search.query(search::TEST_QUERY); search.query(search::TEST_QUERY);
search.limit(EXTERNAL_DOCUMENTS_IDS.len()); search.limit(EXTERNAL_DOCUMENTS_IDS.len());
search.terms_matching_strategy(ALLOW_OPTIONAL_WORDS); search.terms_matching_strategy(ALLOW_OPTIONAL_WORDS);
@ -440,9 +440,9 @@ fn criteria_ascdesc() {
builder.execute(|_| (), || false).unwrap(); builder.execute(|_| (), || false).unwrap();
wtxn.commit().unwrap(); wtxn.commit().unwrap();
let mut rtxn = index.read_txn().unwrap(); let rtxn = index.read_txn().unwrap();
let mut search = Search::new(&mut rtxn, &index); let mut search = Search::new(&rtxn, &index);
search.limit(ASC_DESC_CANDIDATES_THRESHOLD + 1); search.limit(ASC_DESC_CANDIDATES_THRESHOLD + 1);
let SearchResult { documents_ids, .. } = search.execute().unwrap(); let SearchResult { documents_ids, .. } = search.execute().unwrap();

View File

@ -72,9 +72,9 @@ pub fn map_leaf_values<'a>(
map_leaf_values_in_object(value, &selectors, "", &mut mapper); map_leaf_values_in_object(value, &selectors, "", &mut mapper);
} }
pub fn map_leaf_values_in_object<'a>( pub fn map_leaf_values_in_object(
value: &mut Map<String, Value>, value: &mut Map<String, Value>,
selectors: &[&'a str], selectors: &[&str],
base_key: &str, base_key: &str,
mapper: &mut impl FnMut(&str, &mut Value), mapper: &mut impl FnMut(&str, &mut Value),
) { ) {