From 4c454d752d3c10bdfbadfb6425af95780916280b Mon Sep 17 00:00:00 2001 From: Evance Soumaoro Date: Wed, 23 Jun 2021 08:32:51 +0000 Subject: [PATCH] exposing min/max value interface on MultiValuedFastField Reader --- src/fastfield/multivalued/reader.rs | 48 ++++++++++++++++++++++++++++- src/fastfield/reader.rs | 6 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/fastfield/multivalued/reader.rs b/src/fastfield/multivalued/reader.rs index 99fb5d13c8..ad6c99da66 100644 --- a/src/fastfield/multivalued/reader.rs +++ b/src/fastfield/multivalued/reader.rs @@ -46,6 +46,24 @@ impl MultiValuedFastFieldReader { self.vals_reader.get_range_u64(range.start, &mut vals[..]); } + /// Returns the minimum value for this fast field. + /// + /// The min value does not take in account of possible + /// deleted document, and should be considered as a lower bound + /// of the actual mimimum value. + pub fn min_value(&self) -> Item { + self.vals_reader.min_value() + } + + /// Returns the maximum value for this fast field. + /// + /// The max value does not take in account of possible + /// deleted document, and should be considered as an upper bound + /// of the actual maximum value. + pub fn max_value(&self) -> Item { + self.vals_reader.max_value() + } + /// Returns the number of values associated with the document `DocId`. pub fn num_vals(&self, doc: DocId) -> usize { let range = self.range(doc); @@ -71,7 +89,7 @@ impl MultiValueLength for MultiValuedFastFieldReader { mod tests { use crate::core::Index; - use crate::schema::{Facet, Schema, INDEXED}; + use crate::schema::{Cardinality, Facet, IntOptions, Schema, INDEXED}; #[test] fn test_multifastfield_reader() { @@ -126,4 +144,32 @@ mod tests { assert_eq!(&vals[..], &[4]); } } + + #[test] + fn test_multifastfield_reader_min_max() { + let mut schema_builder = Schema::builder(); + let field_options = IntOptions::default() + .set_indexed() + .set_fast(Cardinality::MultiValues); + let item_field = schema_builder.add_i64_field("items", field_options); + let schema = schema_builder.build(); + let index = Index::create_in_ram(schema); + let mut index_writer = index + .writer_for_tests() + .expect("Failed to create index writer."); + index_writer.add_document(doc!( + item_field => 2i64, + item_field => 3i64, + item_field => -2i64, + )); + index_writer.add_document(doc!(item_field => 6i64, item_field => 3i64)); + index_writer.add_document(doc!(item_field => 4i64)); + index_writer.commit().expect("Commit failed"); + let searcher = index.reader().unwrap().searcher(); + let segment_reader = searcher.segment_reader(0); + let field_reader = segment_reader.fast_fields().i64s(item_field).unwrap(); + + assert_eq!(field_reader.min_value(), -2); + assert_eq!(field_reader.max_value(), 6); + } } diff --git a/src/fastfield/reader.rs b/src/fastfield/reader.rs index 9d798787f3..30ae0aba88 100644 --- a/src/fastfield/reader.rs +++ b/src/fastfield/reader.rs @@ -48,9 +48,9 @@ pub trait FastFieldReader: Clone { /// Returns the minimum value for this fast field. /// - /// The max value does not take in account of possible - /// deleted document, and should be considered as an upper bound - /// of the actual maximum value. + /// The min value does not take in account of possible + /// deleted document, and should be considered as a lower bound + /// of the actual mimimum value. fn min_value(&self) -> Item; /// Returns the maximum value for this fast field.