diff --git a/src/fastfield/bytes/writer.rs b/src/fastfield/bytes/writer.rs index f7b1b5d68..3a4de980f 100644 --- a/src/fastfield/bytes/writer.rs +++ b/src/fastfield/bytes/writer.rs @@ -1,6 +1,5 @@ use std::io; -use crate::fastfield::serializer::FastFieldSerializer; use crate::schema::{Document, Field, Value}; use crate::DocId; use crate::{ diff --git a/src/fastfield/mod.rs b/src/fastfield/mod.rs index 786d701ee..1b639ed3d 100644 --- a/src/fastfield/mod.rs +++ b/src/fastfield/mod.rs @@ -35,7 +35,6 @@ pub use self::reader::FastFieldReader; pub use self::readers::FastFieldReaders; pub use self::serializer::CompositeFastFieldSerializer; pub use self::serializer::FastFieldDataAccess; -pub use self::serializer::FastFieldSerializer; pub use self::serializer::FastFieldStats; pub use self::writer::{FastFieldsWriter, IntFastFieldWriter}; use crate::schema::Cardinality; @@ -217,7 +216,6 @@ mod tests { use crate::common::CompositeFile; use crate::common::HasLen; use crate::directory::{Directory, RamDirectory, WritePtr}; - use crate::fastfield::BitpackedFastFieldReader; use crate::merge_policy::NoMergePolicy; use crate::schema::Field; use crate::schema::Schema; diff --git a/src/fastfield/reader.rs b/src/fastfield/reader.rs index e78286811..9af1a4e77 100644 --- a/src/fastfield/reader.rs +++ b/src/fastfield/reader.rs @@ -66,6 +66,7 @@ pub trait FastFieldReader: Clone { pub enum DynamicFastFieldReader { /// Bitpacked compressed fastfield data. Bitpacked(FastFieldReaderCodecWrapper), + /// Linear interpolated values + bitpacked LinearInterpol(FastFieldReaderCodecWrapper), } @@ -141,6 +142,12 @@ pub struct FastFieldReaderCodecWrapper { } impl FastFieldReaderCodecWrapper { + /// Opens a fast field given a file. + pub fn open(file: FileSlice) -> crate::Result { + let mut bytes = file.read_bytes()?; + let _id = u8::deserialize(&mut bytes)?; + Self::open_from_bytes(bytes) + } /// Opens a fast field given the bytes. pub fn open_from_bytes(bytes: OwnedBytes) -> crate::Result { let reader = C::open_from_bytes(bytes.as_slice())?; @@ -224,104 +231,8 @@ impl FastFieldReader } } -/// Trait for accessing a fastfield. -/// -/// Depending on the field type, a different -/// fast field is required. -#[derive(Clone)] -pub struct BitpackedFastFieldReader { - reader: BitpackedReader, - bytes: OwnedBytes, - _phantom: PhantomData, -} - -impl BitpackedFastFieldReader { - /// Opens a fast field given a file. - pub fn open(file: FileSlice) -> crate::Result { - let mut bytes = file.read_bytes()?; - let _id = u8::deserialize(&mut bytes)?; - Self::open_from_bytes(bytes) - } - /// Opens a fast field given the bytes. - pub fn open_from_bytes(bytes: OwnedBytes) -> crate::Result { - let reader = BitpackedReader::open_from_bytes(bytes.as_slice())?; - Ok(BitpackedFastFieldReader { - reader, - bytes, - _phantom: PhantomData, - }) - } - pub(crate) fn get_u64(&self, doc: u64) -> Item { - Item::from_u64(self.reader.get_u64(doc, self.bytes.as_slice())) - } - - /// Internally `multivalued` also use SingleValue Fast fields. - /// It works as follows... A first column contains the list of start index - /// for each document, a second column contains the actual values. - /// - /// The values associated to a given doc, are then - /// `second_column[first_column.get(doc)..first_column.get(doc+1)]`. - /// - /// Which means single value fast field reader can be indexed internally with - /// something different from a `DocId`. For this use case, we want to use `u64` - /// values. - /// - /// See `get_range` for an actual documentation about this method. - pub(crate) fn get_range_u64(&self, start: u64, output: &mut [Item]) { - for (i, out) in output.iter_mut().enumerate() { - *out = self.get_u64(start + (i as u64)); - } - } -} - -impl FastFieldReader for BitpackedFastFieldReader { - /// Return the value associated to the given document. - /// - /// This accessor should return as fast as possible. - /// - /// # Panics - /// - /// May panic if `doc` is greater than the segment - // `maxdoc`. - fn get(&self, doc: DocId) -> Item { - self.get_u64(u64::from(doc)) - } - - /// Fills an output buffer with the fast field values - /// associated with the `DocId` going from - /// `start` to `start + output.len()`. - /// - /// Regardless of the type of `Item`, this method works - /// - transmuting the output array - /// - extracting the `Item`s as if they were `u64` - /// - possibly converting the `u64` value to the right type. - /// - /// # Panics - /// - /// May panic if `start + output.len()` is greater than - /// the segment's `maxdoc`. - fn get_range(&self, start: DocId, output: &mut [Item]) { - self.get_range_u64(u64::from(start), output); - } - - /// 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. - fn min_value(&self) -> Item { - Item::from_u64(self.reader.min_value_u64) - } - - /// 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. - fn max_value(&self) -> Item { - Item::from_u64(self.reader.max_value_u64) - } -} +pub type BitpackedFastFieldReader = + FastFieldReaderCodecWrapper; impl From> for DynamicFastFieldReader { fn from(vals: Vec) -> DynamicFastFieldReader { diff --git a/src/fastfield/serializer/mod.rs b/src/fastfield/serializer/mod.rs index 82e619c27..8d358326e 100644 --- a/src/fastfield/serializer/mod.rs +++ b/src/fastfield/serializer/mod.rs @@ -149,18 +149,6 @@ impl CompositeFastFieldSerializer { } } -/// The FastFieldSerializer trait is the common interface -/// implemented by every fastfield serializer variant. -/// -/// `DynamicFastFieldSerializer` is the enum wrapping all variants. -/// It is used to create an serializer instance. -pub trait FastFieldSerializer { - /// add value to serializer - fn add_val(&mut self, val: u64) -> io::Result<()>; - /// finish serializing a field. - fn close_field(self) -> io::Result<()>; -} - pub struct FastBytesFieldSerializer<'a, W: Write> { write: &'a mut W, }