From 0ad53784e73b6c2da743d9cafee999002a191f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 9 Mar 2023 13:21:21 +0100 Subject: [PATCH] Create a new struct to reduce the type complexity --- .../extract/extract_fid_docid_facet_values.rs | 24 ++++++++++++------- .../src/update/index_documents/extract/mod.rs | 6 ++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/milli/src/update/index_documents/extract/extract_fid_docid_facet_values.rs b/milli/src/update/index_documents/extract/extract_fid_docid_facet_values.rs index be7b44eee..6460af812 100644 --- a/milli/src/update/index_documents/extract/extract_fid_docid_facet_values.rs +++ b/milli/src/update/index_documents/extract/extract_fid_docid_facet_values.rs @@ -16,18 +16,24 @@ use crate::facet::value_encoding::f64_into_bytes; use crate::update::index_documents::{create_writer, writer_into_reader}; use crate::{CboRoaringBitmapCodec, DocumentId, FieldId, Result, BEU32, MAX_FACET_VALUE_LENGTH}; +/// The extracted facet values stored in grenad files by type. +pub struct ExtractedFacetValues { + pub docid_fid_facet_numbers_chunk: grenad::Reader, + pub docid_fid_facet_strings_chunk: grenad::Reader, + pub fid_facet_is_null_docids_chunk: grenad::Reader, + pub fid_facet_exists_docids_chunk: grenad::Reader, +} + /// Extracts the facet values of each faceted field of each document. /// /// Returns the generated grenad reader containing the docid the fid and the orginal value as key /// and the normalized value as value extracted from the given chunk of documents. #[logging_timer::time] -#[allow(clippy::type_complexity)] pub fn extract_fid_docid_facet_values( obkv_documents: grenad::Reader, indexer: GrenadParameters, faceted_fields: &HashSet, -) -> Result<(grenad::Reader, grenad::Reader, grenad::Reader, grenad::Reader)> -{ +) -> Result { let max_memory = indexer.max_memory_by_thread(); let mut fid_docid_facet_numbers_sorter = create_sorter( @@ -134,12 +140,12 @@ pub fn extract_fid_docid_facet_values( } let facet_is_null_docids_reader = writer_into_reader(facet_is_null_docids_writer)?; - Ok(( - sorter_into_reader(fid_docid_facet_numbers_sorter, indexer)?, - sorter_into_reader(fid_docid_facet_strings_sorter, indexer)?, - facet_is_null_docids_reader, - facet_exists_docids_reader, - )) + Ok(ExtractedFacetValues { + docid_fid_facet_numbers_chunk: sorter_into_reader(fid_docid_facet_numbers_sorter, indexer)?, + docid_fid_facet_strings_chunk: sorter_into_reader(fid_docid_facet_strings_sorter, indexer)?, + fid_facet_is_null_docids_chunk: facet_is_null_docids_reader, + fid_facet_exists_docids_chunk: facet_exists_docids_reader, + }) } /// Represent what a document field contains. diff --git a/milli/src/update/index_documents/extract/mod.rs b/milli/src/update/index_documents/extract/mod.rs index c11d08405..4a5c9b64c 100644 --- a/milli/src/update/index_documents/extract/mod.rs +++ b/milli/src/update/index_documents/extract/mod.rs @@ -18,7 +18,7 @@ use rayon::prelude::*; use self::extract_docid_word_positions::extract_docid_word_positions; use self::extract_facet_number_docids::extract_facet_number_docids; use self::extract_facet_string_docids::extract_facet_string_docids; -use self::extract_fid_docid_facet_values::extract_fid_docid_facet_values; +use self::extract_fid_docid_facet_values::{extract_fid_docid_facet_values, ExtractedFacetValues}; use self::extract_fid_word_count_docids::extract_fid_word_count_docids; use self::extract_geo_points::extract_geo_points; use self::extract_word_docids::extract_word_docids; @@ -300,12 +300,12 @@ fn send_and_extract_flattened_documents_data( Ok(docid_word_positions_chunk) }, || { - let ( + let ExtractedFacetValues { docid_fid_facet_numbers_chunk, docid_fid_facet_strings_chunk, fid_facet_is_null_docids_chunk, fid_facet_exists_docids_chunk, - ) = extract_fid_docid_facet_values( + } = extract_fid_docid_facet_values( flattened_documents_chunk.clone(), indexer, faceted_fields,