Skip to main content

ScoreCollector

Struct ScoreCollector 

Source
pub struct ScoreCollector {
    pub k: usize,
    /* private fields */
}
Expand description

Efficient top-k collector using min-heap (internal, scoring-layer)

Maintains the k highest-scoring documents using a min-heap where the lowest score is at the top for O(1) threshold lookup and O(log k) eviction. No deduplication — caller must ensure each doc_id is inserted only once.

This is intentionally separate from TopKCollector in collector.rs: ScoreCollector is used inside MaxScoreExecutor where only (doc_id, score, ordinal) tuples exist — no Scorer trait, no position tracking, and the threshold must be inlined for tight block-max loops. TopKCollector wraps a Scorer and drives the full DocSet/Scorer protocol, collecting positions on demand.

Fields§

§k: usize

Implementations§

Source§

impl ScoreCollector

Source

pub fn new(k: usize) -> Self

Create a new collector for top-k results

Source

pub fn threshold(&self) -> f32

Current score threshold (minimum score to enter top-k)

Source

pub fn insert(&mut self, doc_id: DocId, score: f32) -> bool

Insert a document score. Returns true if inserted in top-k. Caller must ensure each doc_id is inserted only once.

Source

pub fn insert_with_ordinal( &mut self, doc_id: DocId, score: f32, ordinal: u16, ) -> bool

Insert a document score with ordinal. Returns true if inserted in top-k. Caller must ensure each doc_id is inserted only once.

Source

pub fn would_enter(&self, score: f32) -> bool

Check if a score could potentially enter top-k

Source

pub fn would_enter_candidate( &self, doc_id: DocId, score: f32, ordinal: u16, ) -> bool

Check whether this fully identified candidate ranks ahead of the current worst retained entry, including deterministic tie breaks.

Source

pub fn len(&self) -> usize

Get the conceptual heap length, including virtual threshold sentinels.

Source

pub fn real_len(&self) -> usize

Number of real results retained, excluding threshold sentinels.

Source

pub fn is_empty(&self) -> bool

Check if collector is empty

Source

pub fn seed_threshold(&mut self, initial_threshold: f32)

Seed the threshold from a cross-segment shared value.

Logically fills unused slots and replaces retained entries below the new floor with virtual dummy entries. This can be called repeatedly while another segment raises the shared threshold; equal-scoring real candidates win the deterministic doc-id tie break over sentinels.

Source

pub fn into_sorted_results(self) -> Vec<(DocId, f32, u16)>

Convert to sorted top-k results (descending by score). Filters out sentinel entries (doc_id == u32::MAX) from threshold seeding.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more