diff --git a/milli/src/heed_codec/facet/new/mod.rs b/milli/src/heed_codec/facet/new/mod.rs index 5ed6a61f6..04a545564 100644 --- a/milli/src/heed_codec/facet/new/mod.rs +++ b/milli/src/heed_codec/facet/new/mod.rs @@ -1,6 +1,9 @@ +use std::borrow::Cow; +use std::convert::TryFrom; +use std::marker::PhantomData; + use heed::{BytesDecode, BytesEncode}; use roaring::RoaringBitmap; -use std::{borrow::Cow, convert::TryFrom, marker::PhantomData}; pub mod ordered_f64_codec; pub mod str_ref; diff --git a/milli/src/heed_codec/facet/new/ordered_f64_codec.rs b/milli/src/heed_codec/facet/new/ordered_f64_codec.rs index 856a9c0d1..5ac9ffcfc 100644 --- a/milli/src/heed_codec/facet/new/ordered_f64_codec.rs +++ b/milli/src/heed_codec/facet/new/ordered_f64_codec.rs @@ -1,4 +1,5 @@ -use std::{borrow::Cow, convert::TryInto}; +use std::borrow::Cow; +use std::convert::TryInto; use heed::BytesDecode; diff --git a/milli/src/search/facet/facet_distribution_iter.rs b/milli/src/search/facet/facet_distribution_iter.rs index 9e251103c..13ba28019 100644 --- a/milli/src/search/facet/facet_distribution_iter.rs +++ b/milli/src/search/facet/facet_distribution_iter.rs @@ -1,9 +1,10 @@ -use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice}; -use heed::Result; -use roaring::RoaringBitmap; use std::ops::ControlFlow; +use heed::Result; +use roaring::RoaringBitmap; + use super::{get_first_facet_value, get_highest_level}; +use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice}; pub fn iterate_over_facet_distribution<'t, CB>( rtxn: &'t heed::RoTxn<'t>, @@ -108,16 +109,16 @@ where #[cfg(test)] mod tests { - use crate::milli_snap; - use crate::{ - heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec, search::facet::test::FacetIndex, - }; + use std::ops::ControlFlow; + use heed::BytesDecode; use rand::{Rng, SeedableRng}; use roaring::RoaringBitmap; - use std::ops::ControlFlow; use super::iterate_over_facet_distribution; + use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; + use crate::milli_snap; + use crate::search::facet::test::FacetIndex; fn get_simple_index() -> FacetIndex { let index = FacetIndex::::new(4, 8); diff --git a/milli/src/search/facet/facet_range_search.rs b/milli/src/search/facet/facet_range_search.rs index 38c6acdec..20ad23a37 100644 --- a/milli/src/search/facet/facet_range_search.rs +++ b/milli/src/search/facet/facet_range_search.rs @@ -1,18 +1,12 @@ +use std::ops::{Bound, RangeBounds}; + use heed::BytesEncode; use roaring::RoaringBitmap; -use std::ops::Bound; -use std::ops::RangeBounds; -use crate::heed_codec::facet::new::FacetGroupValueCodec; -use crate::heed_codec::facet::new::FacetKey; -use crate::heed_codec::facet::new::FacetKeyCodec; -use crate::heed_codec::facet::new::MyByteSlice; +use super::{get_first_facet_value, get_highest_level, get_last_facet_value}; +use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice}; use crate::Result; -use super::get_first_facet_value; -use super::get_highest_level; -use super::get_last_facet_value; - pub fn find_docids_of_facet_within_bounds<'t, BoundCodec>( rtxn: &'t heed::RoTxn<'t>, db: heed::Database, FacetGroupValueCodec>, @@ -258,17 +252,17 @@ impl<'t, 'b, 'bitmap> FacetRangeSearch<'t, 'b, 'bitmap> { #[cfg(test)] mod tests { - use crate::milli_snap; - use crate::{ - heed_codec::facet::new::{ordered_f64_codec::OrderedF64Codec, FacetKeyCodec}, - search::facet::test::FacetIndex, - snapshot_tests::display_bitmap, - }; - use rand::{Rng, SeedableRng}; - use roaring::RoaringBitmap; use std::ops::Bound; + use rand::{Rng, SeedableRng}; + use roaring::RoaringBitmap; + use super::find_docids_of_facet_within_bounds; + use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; + use crate::heed_codec::facet::new::FacetKeyCodec; + use crate::milli_snap; + use crate::search::facet::test::FacetIndex; + use crate::snapshot_tests::display_bitmap; fn get_simple_index() -> FacetIndex { let index = FacetIndex::::new(4, 8); diff --git a/milli/src/search/facet/facet_sort_ascending.rs b/milli/src/search/facet/facet_sort_ascending.rs index e8618c302..b3cae5d28 100644 --- a/milli/src/search/facet/facet_sort_ascending.rs +++ b/milli/src/search/facet/facet_sort_ascending.rs @@ -1,10 +1,10 @@ -use crate::heed_codec::facet::new::{ - FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, -}; use heed::Result; use roaring::RoaringBitmap; use super::{get_first_facet_value, get_highest_level}; +use crate::heed_codec::facet::new::{ + FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, +}; pub fn ascending_facet_sort<'t>( rtxn: &'t heed::RoTxn<'t>, @@ -83,16 +83,15 @@ impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> { #[cfg(test)] mod tests { - use crate::milli_snap; - use crate::{ - heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec, - search::facet::{facet_sort_ascending::ascending_facet_sort, test::FacetIndex}, - snapshot_tests::display_bitmap, - }; - use rand::Rng; - use rand::SeedableRng; + use rand::{Rng, SeedableRng}; use roaring::RoaringBitmap; + use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; + use crate::milli_snap; + use crate::search::facet::facet_sort_ascending::ascending_facet_sort; + use crate::search::facet::test::FacetIndex; + use crate::snapshot_tests::display_bitmap; + fn get_simple_index() -> FacetIndex { let index = FacetIndex::::new(4, 8); let mut txn = index.env.write_txn().unwrap(); diff --git a/milli/src/search/facet/facet_sort_descending.rs b/milli/src/search/facet/facet_sort_descending.rs index b8bae2f9d..d68c9bdad 100644 --- a/milli/src/search/facet/facet_sort_descending.rs +++ b/milli/src/search/facet/facet_sort_descending.rs @@ -1,12 +1,12 @@ use std::ops::Bound; -use crate::heed_codec::facet::new::{ - FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, -}; use heed::Result; use roaring::RoaringBitmap; use super::{get_first_facet_value, get_highest_level, get_last_facet_value}; +use crate::heed_codec::facet::new::{ + FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, +}; pub fn descending_facet_sort<'t>( rtxn: &'t heed::RoTxn<'t>, @@ -111,16 +111,16 @@ impl<'t> Iterator for DescendingFacetSort<'t> { #[cfg(test)] mod tests { - use crate::milli_snap; - use crate::{ - heed_codec::facet::new::{ordered_f64_codec::OrderedF64Codec, FacetKeyCodec, MyByteSlice}, - search::facet::{facet_sort_descending::descending_facet_sort, test::FacetIndex}, - snapshot_tests::display_bitmap, - }; - use rand::Rng; - use rand::SeedableRng; + use rand::{Rng, SeedableRng}; use roaring::RoaringBitmap; + use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; + use crate::heed_codec::facet::new::{FacetKeyCodec, MyByteSlice}; + use crate::milli_snap; + use crate::search::facet::facet_sort_descending::descending_facet_sort; + use crate::search::facet::test::FacetIndex; + use crate::snapshot_tests::display_bitmap; + fn get_simple_index() -> FacetIndex { let index = FacetIndex::::new(4, 8); let mut txn = index.env.write_txn().unwrap(); diff --git a/milli/src/search/facet/filter.rs b/milli/src/search/facet/filter.rs index 6ec626a5c..6a10b7097 100644 --- a/milli/src/search/facet/filter.rs +++ b/milli/src/search/facet/filter.rs @@ -1,18 +1,18 @@ -use either::Either; -pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Token}; -use heed::types::DecodeIgnore; -use roaring::RoaringBitmap; use std::collections::HashSet; use std::fmt::{Debug, Display}; use std::ops::Bound::{self, Excluded, Included}; +use either::Either; +pub use filter_parser::{Condition, Error as FPError, FilterCondition, Span, Token}; +use heed::types::DecodeIgnore; +use roaring::RoaringBitmap; + +use super::facet_range_search; use crate::error::{Error, UserError}; use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKey, FacetKeyCodec}; use crate::{distance_between_two_points, lat_lng_to_xyz, FieldId, Index, Result}; -use super::facet_range_search; - /// The maximum number of filters the filter AST can process. const MAX_FILTER_DEPTH: usize = 2000; diff --git a/milli/src/search/facet/mod.rs b/milli/src/search/facet/mod.rs index 42c0f065a..78cd8fd4b 100644 --- a/milli/src/search/facet/mod.rs +++ b/milli/src/search/facet/mod.rs @@ -1,10 +1,9 @@ use heed::types::ByteSlice; use heed::{BytesDecode, RoTxn}; -use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKeyCodec, MyByteSlice}; - pub use self::facet_distribution::{FacetDistribution, DEFAULT_VALUES_PER_FACET}; pub use self::filter::Filter; +use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKeyCodec, MyByteSlice}; mod facet_distribution; mod facet_distribution_iter; @@ -78,17 +77,18 @@ pub(crate) fn get_highest_level<'t>( #[cfg(test)] pub mod test { - use crate::update::FacetsUpdateIncremental; + use std::fmt::Display; + use std::marker::PhantomData; + use std::rc::Rc; + use heed::{BytesDecode, BytesEncode, Env, RwTxn}; use roaring::RoaringBitmap; - use std::{fmt::Display, marker::PhantomData, rc::Rc}; - use crate::{ - heed_codec::facet::new::{ - FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, - }, - snapshot_tests::display_bitmap, + use crate::heed_codec::facet::new::{ + FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, }; + use crate::snapshot_tests::display_bitmap; + use crate::update::FacetsUpdateIncremental; pub struct FacetIndex where diff --git a/milli/src/snapshot_tests.rs b/milli/src/snapshot_tests.rs index f35bda2e7..d054e63b5 100644 --- a/milli/src/snapshot_tests.rs +++ b/milli/src/snapshot_tests.rs @@ -1,10 +1,12 @@ -use crate::heed_codec::facet::new::{FacetGroupValue, FacetKey}; -use crate::{make_db_snap_from_iter, ExternalDocumentsIds, Index}; -use roaring::RoaringBitmap; use std::borrow::Cow; use std::fmt::Write; use std::path::Path; +use roaring::RoaringBitmap; + +use crate::heed_codec::facet::new::{FacetGroupValue, FacetKey}; +use crate::{make_db_snap_from_iter, ExternalDocumentsIds, Index}; + #[track_caller] pub fn default_db_snapshot_settings_for_test(name: Option<&str>) -> (insta::Settings, String) { let mut settings = insta::Settings::clone_current(); diff --git a/milli/src/update/facet/bulk.rs b/milli/src/update/facet/bulk.rs index b8acffbaf..f93ee735e 100644 --- a/milli/src/update/facet/bulk.rs +++ b/milli/src/update/facet/bulk.rs @@ -1,3 +1,14 @@ +use std::cmp; +use std::fs::File; +use std::num::NonZeroUsize; + +use grenad::CompressionType; +use heed::types::ByteSlice; +use heed::{BytesEncode, Error, RoTxn}; +use log::debug; +use roaring::RoaringBitmap; +use time::OffsetDateTime; + use crate::error::InternalError; use crate::facet::FacetType; use crate::heed_codec::facet::new::{ @@ -5,15 +16,6 @@ use crate::heed_codec::facet::new::{ }; use crate::update::index_documents::{create_writer, write_into_lmdb_database, writer_into_reader}; use crate::{FieldId, Index, Result}; -use grenad::CompressionType; -use heed::types::ByteSlice; -use heed::{BytesEncode, Error, RoTxn}; -use log::debug; -use roaring::RoaringBitmap; -use std::cmp; -use std::fs::File; -use std::num::NonZeroUsize; -use time::OffsetDateTime; pub struct FacetsUpdateBulk<'i> { index: &'i Index, diff --git a/milli/src/update/facet/incremental.rs b/milli/src/update/facet/incremental.rs index 712d7271c..3493db0f7 100644 --- a/milli/src/update/facet/incremental.rs +++ b/milli/src/update/facet/incremental.rs @@ -1,11 +1,12 @@ +use heed::types::ByteSlice; +use heed::{BytesDecode, Error, RoTxn, RwTxn}; +use roaring::RoaringBitmap; + use crate::heed_codec::facet::new::{ FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, }; use crate::search::facet::get_highest_level; use crate::Result; -use heed::Error; -use heed::{types::ByteSlice, BytesDecode, RoTxn, RwTxn}; -use roaring::RoaringBitmap; enum InsertionResult { InPlace, @@ -462,19 +463,19 @@ impl FacetsUpdateIncremental { #[cfg(test)] mod tests { - use crate::milli_snap; - use crate::{ - heed_codec::facet::new::{ - ordered_f64_codec::OrderedF64Codec, str_ref::StrRefCodec, FacetGroupValueCodec, - FacetKeyCodec, MyByteSlice, - }, - search::facet::{get_highest_level, test::FacetIndex}, - }; - use heed::{types::ByteSlice, BytesDecode, BytesEncode}; - use rand::Rng; - use rand::{seq::SliceRandom, SeedableRng}; + use heed::types::ByteSlice; + use heed::{BytesDecode, BytesEncode}; + use rand::seq::SliceRandom; + use rand::{Rng, SeedableRng}; use roaring::RoaringBitmap; + use crate::heed_codec::facet::new::ordered_f64_codec::OrderedF64Codec; + use crate::heed_codec::facet::new::str_ref::StrRefCodec; + use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKeyCodec, MyByteSlice}; + use crate::milli_snap; + use crate::search::facet::get_highest_level; + use crate::search::facet::test::FacetIndex; + pub fn verify_structure_validity(index: &FacetIndex, field_id: u16) where for<'a> C: BytesDecode<'a> + BytesEncode<'a, EItem = >::DItem>, diff --git a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs index fe42801e7..591f44c74 100644 --- a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs +++ b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs @@ -1,11 +1,13 @@ +use std::fs::File; +use std::io; + +use heed::BytesEncode; + use super::helpers::{create_sorter, sorter_into_reader, try_split_array_at, GrenadParameters}; use crate::heed_codec::facet::new::str_ref::StrRefCodec; use crate::heed_codec::facet::new::{FacetKey, FacetKeyCodec}; use crate::update::index_documents::merge_cbo_roaring_bitmaps; use crate::{FieldId, Result}; -use heed::BytesEncode; -use std::fs::File; -use std::io; /// Extracts the facet string and the documents ids where this facet string appear. ///