This commit is contained in:
Paul Masurel
2026-01-16 13:45:51 +01:00
parent a5ccb62c99
commit 6f00d96127
4 changed files with 64 additions and 3 deletions

View File

@@ -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<OwnedBytes>,
) -> crate::Result<Box<dyn Postings>>;
}
impl<TPostingsCodec: PostingsCodec> CodecPostingsLoader for TPostingsCodec {
fn load_postings_type_erased(&self,
doc_freq: u32,
postings_data: OwnedBytes,
record_option: IndexRecordOption,
requested_option: IndexRecordOption,
positions_data: Option<OwnedBytes>,
) -> crate::Result<Box<dyn Postings>> {
let postings: <Self as PostingsCodec>::Postings = self.load_postings(doc_freq, postings_data, record_option, requested_option, positions_data)?;
let boxed_postings: Box<dyn Postings> = Box::new(postings);
Ok(boxed_postings)
}
}

View File

@@ -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<Self::PostingsReader>;
fn load_postings(&self,
doc_freq: u32,
postings_data: OwnedBytes,
record_option: IndexRecordOption,
requested_option: IndexRecordOption,
positions_data: Option<OwnedBytes>) -> io::Result<Self::Postings>;
}
pub trait PostingsSerializer {

View File

@@ -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<Self::PostingsReader> {
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<common::OwnedBytes>) -> io::Result<Self::Postings> {
// 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,
))
}
}

View File

@@ -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 {