From 68cbcdf08b860ce42458ffc0868a00086696b10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Thu, 1 Sep 2022 08:34:26 +0200 Subject: [PATCH] Fix compile errors/warnings in http-ui and infos --- milli/src/search/facet/mod.rs | 4 +-- milli/src/update/delete_documents.rs | 46 +++++++++++++++------------- milli/src/update/facet/bulk.rs | 38 +++++++++++------------ 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/milli/src/search/facet/mod.rs b/milli/src/search/facet/mod.rs index 2ca6c0689..b03302ca1 100644 --- a/milli/src/search/facet/mod.rs +++ b/milli/src/search/facet/mod.rs @@ -82,7 +82,6 @@ mod test { use heed::{BytesDecode, BytesEncode, Env, RwTxn}; use roaring::RoaringBitmap; use std::{fmt::Display, marker::PhantomData, rc::Rc}; - use tempfile::TempDir; use crate::{ heed_codec::facet::new::{ @@ -113,8 +112,9 @@ mod test { for<'a> BoundCodec: BytesEncode<'a> + BytesDecode<'a, DItem = >::EItem>, { + #[cfg(all(test, fuzzing))] pub fn open_from_tempdir( - tempdir: Rc, + tempdir: Rc, group_size: u8, max_group_size: u8, ) -> FacetIndex { diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index bb18ed80f..531fd2b74 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -2,7 +2,7 @@ use std::collections::btree_map::Entry; use fst::IntoStreamer; use heed::types::{ByteSlice, Str}; -use heed::{Database, RwTxn}; +use heed::Database; use roaring::RoaringBitmap; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -10,6 +10,7 @@ use time::OffsetDateTime; use super::{ClearDocuments, FacetsUpdateBulk}; use crate::error::{InternalError, UserError}; +use crate::facet::FacetType; use crate::heed_codec::facet::new::{FacetGroupValueCodec, FacetKeyCodec, MyByteSlice}; use crate::heed_codec::CboRoaringBitmapCodec; use crate::index::{db_name, main_key}; @@ -185,9 +186,9 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { prefix_word_pair_proximity_docids, word_position_docids, word_prefix_position_docids, - facet_id_f64_docids, + facet_id_f64_docids: _, facet_id_exists_docids, - facet_id_string_docids, + facet_id_string_docids: _, field_id_docid_facet_f64s, field_id_docid_facet_strings, documents, @@ -440,22 +441,16 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { self.index.put_geo_faceted_documents_ids(self.wtxn, &geo_faceted_doc_ids)?; } - remove_docids_from_facet_id_docids( - self.wtxn, - self.index, - facet_id_f64_docids.remap_key_type::>(), - &self.to_delete_docids, - fields_ids_map.clone(), - Index::put_number_faceted_documents_ids, - )?; - remove_docids_from_facet_id_docids( - self.wtxn, - self.index, - facet_id_string_docids.remap_key_type::>(), - &self.to_delete_docids, - fields_ids_map.clone(), - Index::put_string_faceted_documents_ids, - )?; + for facet_type in [FacetType::Number, FacetType::String] { + remove_docids_from_facet_id_docids( + self.wtxn, + self.index, + &self.to_delete_docids, + fields_ids_map.clone(), + facet_type, + )?; + } + // We delete the documents ids that are under the facet field id values. remove_docids_from_facet_id_exists_docids( self.wtxn, @@ -613,11 +608,18 @@ where fn remove_docids_from_facet_id_docids<'a>( wtxn: &'a mut heed::RwTxn, index: &Index, - db: heed::Database, FacetGroupValueCodec>, to_remove: &RoaringBitmap, fields_ids_map: FieldsIdsMap, - put_faceted_docids_in_main: fn(&Index, &mut RwTxn, FieldId, &RoaringBitmap) -> heed::Result<()>, + facet_type: FacetType, ) -> Result<()> { + let db = match facet_type { + FacetType::String => { + index.facet_id_string_docids.remap_key_type::>() + } + FacetType::Number => { + index.facet_id_f64_docids.remap_key_type::>() + } + }; let mut modified = false; for field_id in fields_ids_map.ids() { let mut level0_prefix = vec![]; @@ -646,7 +648,7 @@ fn remove_docids_from_facet_id_docids<'a>( if !modified { return Ok(()); } - let builder = FacetsUpdateBulk::new(index, db, put_faceted_docids_in_main); + let builder = FacetsUpdateBulk::new(index, facet_type); builder.execute(wtxn)?; Ok(()) diff --git a/milli/src/update/facet/bulk.rs b/milli/src/update/facet/bulk.rs index b3e932dc2..b8acffbaf 100644 --- a/milli/src/update/facet/bulk.rs +++ b/milli/src/update/facet/bulk.rs @@ -1,4 +1,5 @@ use crate::error::InternalError; +use crate::facet::FacetType; use crate::heed_codec::facet::new::{ FacetGroupValue, FacetGroupValueCodec, FacetKey, FacetKeyCodec, MyByteSlice, }; @@ -6,7 +7,7 @@ use crate::update::index_documents::{create_writer, write_into_lmdb_database, wr use crate::{FieldId, Index, Result}; use grenad::CompressionType; use heed::types::ByteSlice; -use heed::{BytesEncode, Error, RoTxn, RwTxn}; +use heed::{BytesEncode, Error, RoTxn}; use log::debug; use roaring::RoaringBitmap; use std::cmp; @@ -21,28 +22,26 @@ pub struct FacetsUpdateBulk<'i> { pub(crate) chunk_compression_level: Option, level_group_size: usize, min_level_size: usize, - put_faceted_docids_in_main: fn(&Index, &mut RwTxn, FieldId, &RoaringBitmap) -> heed::Result<()>, + facet_type: FacetType, } impl<'i> FacetsUpdateBulk<'i> { - pub fn new( - index: &'i Index, - database: heed::Database, FacetGroupValueCodec>, - put_faceted_docids_in_main: fn( - &Index, - &mut RwTxn, - FieldId, - &RoaringBitmap, - ) -> heed::Result<()>, - ) -> FacetsUpdateBulk<'i> { + pub fn new(index: &'i Index, facet_type: FacetType) -> FacetsUpdateBulk<'i> { FacetsUpdateBulk { index, - database, + database: match facet_type { + FacetType::String => { + index.facet_id_string_docids.remap_key_type::>() + } + FacetType::Number => { + index.facet_id_f64_docids.remap_key_type::>() + } + }, chunk_compression_type: CompressionType::None, chunk_compression_level: None, level_group_size: 4, min_level_size: 5, - put_faceted_docids_in_main, + facet_type, } } @@ -86,12 +85,11 @@ impl<'i> FacetsUpdateBulk<'i> { let (level_readers, all_docids) = self.compute_levels_for_field_id(field_id, &nested_wtxn)?; - (self.put_faceted_docids_in_main)( - &self.index, - &mut nested_wtxn, - field_id, - &all_docids, - )?; + let put_docids_fn = match self.facet_type { + FacetType::Number => Index::put_number_faceted_documents_ids, + FacetType::String => Index::put_string_faceted_documents_ids, + }; + put_docids_fn(&self.index, &mut nested_wtxn, field_id, &all_docids)?; for level_reader in level_readers { // TODO: append instead of write with merge