From 6f00d961279ea95c3cb38bb5f33f966f3337071b Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Fri, 16 Jan 2026 13:45:51 +0100 Subject: [PATCH] blop --- src/codec/mod.rs | 28 +++++++++++++++++++++++++++- src/codec/postings/mod.rs | 10 +++++++++- src/codec/standard/postings/mod.rs | 27 +++++++++++++++++++++++++++ src/docset.rs | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/codec/mod.rs b/src/codec/mod.rs index 4e303f1d2..77a3d6414 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -3,10 +3,11 @@ pub mod standard; use std::borrow::Cow; +use common::OwnedBytes; use serde::{Deserialize, Serialize}; pub use standard::StandardCodec; -use crate::codec::postings::PostingsCodec; +use crate::{codec::postings::PostingsCodec, postings::Postings, schema::IndexRecordOption}; pub trait Codec: Clone + std::fmt::Debug + Send + Sync + 'static { type PostingsCodec: PostingsCodec; @@ -19,6 +20,7 @@ pub trait Codec: Clone + std::fmt::Debug + Send + Sync + 'static { fn postings_codec(&self) -> &Self::PostingsCodec; } + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct CodecConfiguration { name: Cow<'static, str>, @@ -51,3 +53,27 @@ impl Default for CodecConfiguration { CodecConfiguration::from_codec(&StandardCodec) } } + +pub trait CodecPostingsLoader { + fn load_postings_type_erased(&self, + doc_freq: u32, + postings_data: OwnedBytes, + record_option: IndexRecordOption, + requested_option: IndexRecordOption, + positions_data: Option, + ) -> crate::Result>; +} + +impl CodecPostingsLoader for TPostingsCodec { + fn load_postings_type_erased(&self, + doc_freq: u32, + postings_data: OwnedBytes, + record_option: IndexRecordOption, + requested_option: IndexRecordOption, + positions_data: Option, + ) -> crate::Result> { + let postings: ::Postings = self.load_postings(doc_freq, postings_data, record_option, requested_option, positions_data)?; + let boxed_postings: Box = Box::new(postings); + Ok(boxed_postings) + } +} diff --git a/src/codec/postings/mod.rs b/src/codec/postings/mod.rs index 528461da5..0ec7702b5 100644 --- a/src/codec/postings/mod.rs +++ b/src/codec/postings/mod.rs @@ -3,7 +3,7 @@ use std::io; use common::OwnedBytes; use crate::fieldnorm::FieldNormReader; -use crate::postings::FreqReadingOption; +use crate::postings::{FreqReadingOption, Postings}; use crate::query::Bm25Weight; use crate::schema::IndexRecordOption; use crate::{DocId, Score}; @@ -11,6 +11,7 @@ use crate::{DocId, Score}; pub trait PostingsCodec { type PostingsSerializer: PostingsSerializer; type PostingsReader: PostingsReader; + type Postings: Postings; fn new_serializer( &self, @@ -32,6 +33,13 @@ pub trait PostingsCodec { record_option: IndexRecordOption, requested_option: IndexRecordOption, ) -> std::io::Result; + + fn load_postings(&self, + doc_freq: u32, + postings_data: OwnedBytes, + record_option: IndexRecordOption, + requested_option: IndexRecordOption, + positions_data: Option) -> io::Result; } pub trait PostingsSerializer { diff --git a/src/codec/standard/postings/mod.rs b/src/codec/standard/postings/mod.rs index 463d05255..bc9cc8afc 100644 --- a/src/codec/standard/postings/mod.rs +++ b/src/codec/standard/postings/mod.rs @@ -1,5 +1,9 @@ +use std::io; + use crate::codec::postings::PostingsCodec; use crate::fieldnorm::FieldNormReader; +use crate::positions::PositionReader; +use crate::postings::SegmentPostings; use crate::schema::IndexRecordOption; use crate::Score; @@ -16,6 +20,7 @@ pub struct StandardPostingsCodec; impl PostingsCodec for StandardPostingsCodec { type PostingsSerializer = StandardPostingsSerializer; type PostingsReader = StandardPostingsReader; + type Postings = SegmentPostings; fn new_serializer( &self, @@ -34,4 +39,26 @@ impl PostingsCodec for StandardPostingsCodec { ) -> std::io::Result { StandardPostingsReader::open(doc_freq, data, record_option, requested_option) } + + fn load_postings(&self, + doc_freq: u32, + postings_data: common::OwnedBytes, + record_option: IndexRecordOption, + requested_option: IndexRecordOption, + positions_data_opt: Option) -> io::Result { + // Rationalize record_option/requested_option. + let record_option = requested_option.downgrade(record_option); + let block_segment_postings = StandardPostingsReader::open( + doc_freq, + postings_data, + record_option, + requested_option, + )?; + let position_reader = + positions_data_opt.map(PositionReader::open).transpose()?; + Ok(SegmentPostings::from_block_postings( + block_segment_postings, + position_reader, + )) + } } diff --git a/src/docset.rs b/src/docset.rs index 0926b6df7..01a988be2 100644 --- a/src/docset.rs +++ b/src/docset.rs @@ -108,7 +108,7 @@ pub trait DocSet: Send { buffer.len() } - // comment on the size of the bitset + /// TODO comment on the size of the bitset fn fill_bitset(&mut self, bitset: &mut BitSet) { let mut doc = self.doc(); while doc != TERMINATED {