Skip to main content

Searcher

Struct Searcher 

Source
pub struct Searcher<D: Directory + 'static> { /* private fields */ }
Expand description

Searcher - provides search over loaded segments

For wasm/read-only use, create via Searcher::open(). For native use with Index, this is created via IndexReader.

Implementations§

Source§

impl<D: Directory + 'static> Searcher<D>

Source

pub async fn open( directory: Arc<D>, schema: Arc<Schema>, segment_ids: &[String], term_cache_blocks: usize, ) -> Result<Self>

Create a Searcher directly from segment IDs

This is a simpler initialization path that doesn’t require SegmentManager. Use this for read-only access to pre-built indexes.

Source

pub fn schema(&self) -> &Schema

Get the schema

Source

pub fn schema_arc(&self) -> Arc<Schema> ⓘ

Source

pub fn segment_readers(&self) -> &[Arc<SegmentReader>]

Get segment readers

Source

pub fn default_fields(&self) -> &[Field]

Get default fields for search

Source

pub fn tokenizers(&self) -> &TokenizerRegistry

Get tokenizer registry

Source

pub fn trained_centroids(&self) -> &FxHashMap<u32, Arc<CoarseCentroids>>

Get trained centroids

Source

pub fn trained_binary_quantizers( &self, ) -> &FxHashMap<u32, Arc<BinaryCoarseQuantizer>>

Source

pub fn global_stats(&self) -> &Arc<LazyGlobalStats> ⓘ

Get lazy global statistics for cross-segment IDF computation

Source

pub fn num_docs(&self) -> u32

Get total document count across all segments

Source

pub fn segment_map(&self) -> &FxHashMap<u128, usize>

Get O(1) segment_id → index map (used by reranker)

Source

pub fn num_segments(&self) -> usize

Get number of segments

Source

pub async fn doc( &self, segment_id: u128, doc_id: u32, ) -> Result<Option<Document>>

Get a document by (segment_id, local_doc_id)

Source

pub async fn search( &self, query: &dyn Query, limit: usize, ) -> Result<Vec<SearchResult>>

Search across all segments and return aggregated results

Source

pub async fn search_with_count( &self, query: &dyn Query, limit: usize, ) -> Result<(Vec<SearchResult>, u32)>

Search across all segments and return (results, total_seen) total_seen is the number of documents that were scored across all segments

Source

pub async fn search_with_offset( &self, query: &dyn Query, limit: usize, offset: usize, ) -> Result<Vec<SearchResult>>

Search with offset for pagination

Source

pub async fn search_with_offset_and_count( &self, query: &dyn Query, limit: usize, offset: usize, ) -> Result<(Vec<SearchResult>, u32)>

Search with offset and return (results, total_seen)

Source

pub async fn search_with_positions( &self, query: &dyn Query, limit: usize, ) -> Result<(Vec<SearchResult>, u32)>

Search with positions (ordinal tracking) and return (results, total_seen)

Use this when you need per-ordinal scores for multi-valued fields.

Source

pub async fn search_with_positions_budgeted( &self, query: &dyn Query, limit: usize, deadline: Option<Instant>, ) -> Result<(Vec<SearchResult>, u32, bool)>

search_with_positions under a wall-clock budget (anytime mode). Returns (results, seen, truncated); truncated is set when an executor stopped scoring at the deadline, in which case the results are the best found so far rather than the exact top-k.

Source

pub async fn search_with_count_budgeted( &self, query: &dyn Query, limit: usize, deadline: Option<Instant>, ) -> Result<(Vec<SearchResult>, u32, bool)>

search_with_count under a wall-clock budget; see Self::search_with_positions_budgeted.

Source

pub async fn search_with_positions_budgeted_stats( &self, query: &dyn Query, limit: usize, deadline: Option<Instant>, stats: Option<Arc<GlobalStats>>, ) -> Result<(Vec<SearchResult>, u32, bool)>

Self::search_with_positions_budgeted with externally supplied text statistics (a broker’s cross-shard document frequencies); they replace the searcher’s own segment-aggregated statistics.

Source

pub async fn search_with_count_budgeted_stats( &self, query: &dyn Query, limit: usize, deadline: Option<Instant>, stats: Option<Arc<GlobalStats>>, ) -> Result<(Vec<SearchResult>, u32, bool)>

Self::search_with_count_budgeted with externally supplied text statistics.

Source

pub fn query_text_stats( &self, query: &dyn Query, stats_override: Option<Arc<GlobalStats>>, ) -> Option<Arc<GlobalStats>>

Text statistics a query scores with: the caller’s override when given, otherwise document frequencies, corpus sizes and average lengths aggregated over every segment of this searcher (None for a single segment, whose local statistics already are the whole).

Source

pub fn search_with_offset_and_count_sync( &self, query: &dyn Query, limit: usize, offset: usize, ) -> Result<(Vec<SearchResult>, u32)>

Synchronous search across all segments using rayon for parallelism.

This is the async-free boundary — no tokio involvement from here down.

Source

pub async fn search_fused( &self, queries: &[(&dyn Query, f32)], fetch_limit: usize, limit: usize, method: FusionMethod, combiner: MultiValueCombiner, ) -> Result<Vec<SearchResult>>

Hybrid search: run several queries independently and fuse their ranked lists (union) into a single top-limit result.

Unlike Self::search_and_rerank — which can only re-score documents the first-stage query already found — fusion keeps documents found by any of the queries. Typical use is sparse (BM25/SPLADE) + dense vector hybrid retrieval with FusionMethod::Rrf { k: 60.0 }.

Fusion happens at chunk granularity: per-ordinal scores are collected from each sub-query, fused per (doc, ordinal) key, then combined into a doc score with combiner (MultiValueCombiner::Max recommended — same-chunk corroboration across verticals compounds, scattered noise does not). Fused results carry per-chunk positions.

Each query is paired with a weight scaling its contribution. fetch_limit is the per-query candidate depth. Request-facing adapters default to at most crate::query::MAX_CANDIDATE_OVERSUBSCRIPTION times the result window and never multiply an existing rerank pool again.

Source

pub async fn search_fused_with_count( &self, queries: &[(&dyn Query, f32)], fetch_limit: usize, limit: usize, method: FusionMethod, combiner: MultiValueCombiner, ) -> Result<(Vec<SearchResult>, u32)>

Fusion variant that also returns the aggregate number of documents scored by all sub-queries. This lets request-facing callers use the parallel fusion path without rerunning sub-queries for observability.

Source

pub fn fuse_candidate_lists( &self, lists: &[(&[SearchResult], f32)], method: FusionMethod, combiner: MultiValueCombiner, limit: usize, ) -> Result<Vec<SearchResult>>

Fuse retained nomination lists on this searcher’s shared CPU pool.

Source

pub fn rrf_scores_for_hits( &self, lists: &[RrfRankedList<'_>], selected: &[(u128, u32)], k: f32, combiner: MultiValueCombiner, ) -> Result<Vec<RrfScore>>

Attribute organic RRF votes without repeating retrieval or changing L1.

Source

pub async fn search_candidate_union( &self, queries: &[Arc<dyn Query>], depth: usize, stats: Arc<GlobalStats>, ) -> Result<(Vec<SearchResult>, u32)>

Retrieve independent branches and retain the complete bounded document union. No rank fusion or cross-branch top-k runs before feature scoring.

Source

pub async fn search_candidate_lists( &self, queries: &[Arc<dyn Query>], depth: usize, stats: Option<Arc<GlobalStats>>, ) -> Result<Vec<(Vec<SearchResult>, u32)>>

Independent nominated lists for coordinator-side global fusion. This uses the same bounded parallel retrieval as candidate backfill.

Source

pub fn merge_candidate_lists<T: Into<SearchResult> + Borrow<SearchResult>>( &self, lists: impl IntoIterator<Item = impl IntoIterator<Item = T>>, ) -> Result<Vec<SearchResult>>

Source

pub async fn search_and_rerank( &self, query: &dyn Query, l1_limit: usize, final_limit: usize, config: &RerankerConfig, ) -> Result<(Vec<SearchResult>, u32)>

Two-stage search: L1 retrieval + L2 dense vector reranking

Runs the query to get l1_limit candidates, then reranks by exact dense vector distance and returns the top final_limit results.

Source

pub async fn query( &self, query_str: &str, limit: usize, ) -> Result<SearchResponse>

Parse query string and search (convenience method)

Source

pub async fn query_offset( &self, query_str: &str, limit: usize, offset: usize, ) -> Result<SearchResponse>

Parse query string and search with offset (convenience method)

Source

pub fn query_parser(&self) -> QueryLanguageParser

Get query parser for this searcher

Source

pub async fn get_document( &self, address: &DocAddress, ) -> Result<Option<Document>>

Get a document by address (segment_id + local doc_id)

Source

pub async fn get_document_with_fields( &self, address: &DocAddress, fields: Option<&FxHashSet<u32>>, ) -> Result<Option<Document>>

Get a document by address, hydrating only the specified field IDs.

If fields is None, all fields are hydrated (including dense vectors). If fields is Some(set), only dense vector fields in the set are read from flat storage — skipping expensive mmap reads for unrequested vectors.

Source§

impl<D: Directory + 'static> Searcher<D>

Source

pub async fn candidate_text_stats( &self, plan: &CandidateScoringPlan, ) -> Result<Arc<GlobalStats>>

Complete BM25 statistics over this immutable snapshot, including on native-async and WASM where the synchronous lazy cache is unavailable.

Source

pub async fn score_candidates( &self, candidates: &[SearchResult], plan: &CandidateScoringPlan, stats: Option<Arc<GlobalStats>>, ) -> Result<Vec<ScoredCandidate>>

Score all requested documents against every named branch, including fields which did not nominate them. Addresses must belong to this snapshot; stale addresses and budget overflows fail explicitly.

Source

pub async fn score_candidates_with_retrieved( &self, candidates: &[SearchResult], plan: &CandidateScoringPlan, stats: Option<Arc<GlobalStats>>, retrieved: &[(usize, &[SearchResult])], ) -> Result<Vec<ScoredCandidate>>

Preserve scores from named retrieval branches, then optionally probe only missing logical cells. Branch indices refer to plan.features.

Source

pub async fn score_candidates_with_retrieved_and_rrf( &self, candidates: &[SearchResult], plan: &CandidateScoringPlan, stats: Option<Arc<GlobalStats>>, retrieved: &[(usize, &[SearchResult])], rrf: Option<&[RrfScore]>, ) -> Result<Vec<ScoredCandidate>>

Supply organic RRF features to the same L1 scorer before any top-k.

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for Searcher<D>

§

impl<D> !UnwindSafe for Searcher<D>

§

impl<D> Freeze for Searcher<D>
where PhantomData<D>: Freeze,

§

impl<D> Send for Searcher<D>
where PhantomData<D>: Send,

§

impl<D> Sync for Searcher<D>
where PhantomData<D>: Sync,

§

impl<D> Unpin for Searcher<D>
where PhantomData<D>: Unpin,

§

impl<D> UnsafeUnpin for Searcher<D>

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> ErasedDestructor for T
where T: 'static,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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