Struct tantivy::Searcher

source ·
pub struct Searcher { /* private fields */ }
Expand description

Holds a list of SegmentReaders ready for search.

It guarantees that the Segment will not be removed before the destruction of the Searcher.

Implementations§

source§

impl Searcher

source

pub fn index(&self) -> &Index

Returns the Index associated with the Searcher

source

pub fn generation(&self) -> &SearcherGeneration

SearcherGeneration which identifies the version of the snapshot held by this Searcher.

source

pub fn doc<D: DocumentDeserialize>(&self, doc_address: DocAddress) -> Result<D>

Fetches a document from tantivy’s store given a DocAddress.

The searcher uses the segment ordinal to route the request to the right Segment.

source

pub fn doc_store_cache_stats(&self) -> CacheStats

The cache stats for the underlying store reader.

Aggregates the sum for each segment store reader.

source

pub fn schema(&self) -> &Schema

Access the schema associated with the index of this searcher.

source

pub fn num_docs(&self) -> u64

Returns the overall number of documents in the index.

source

pub fn doc_freq(&self, term: &Term) -> Result<u64>

Return the overall number of documents containing the given term.

source

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

Return the list of segment readers

source

pub fn segment_reader(&self, segment_ord: u32) -> &SegmentReader

Returns the segment_reader associated with the given segment_ord

source

pub fn search<C: Collector>( &self, query: &dyn Query, collector: &C ) -> Result<C::Fruit>

Runs a query on the segment readers wrapped by the searcher.

Search works as follows :

First the weight object associated with the query is created.

Then, the query loops over the segments and for each segment :

  • setup the collector and informs it that the segment being processed has changed.
  • creates a SegmentCollector for collecting documents associated with the segment
  • creates a Scorer object associated for this segment
  • iterate through the matched documents and push them to the segment collector.

Finally, the Collector merges each of the child collectors into itself for result usability by the caller.

source

pub fn search_with_statistics_provider<C: Collector>( &self, query: &dyn Query, collector: &C, statistics_provider: &dyn Bm25StatisticsProvider ) -> Result<C::Fruit>

Same as search(...) but allows specifying a Bm25StatisticsProvider.

This can be used to adjust the statistics used in computing BM25 scores.

source

pub fn search_with_executor<C: Collector>( &self, query: &dyn Query, collector: &C, executor: &Executor, enabled_scoring: EnableScoring<'_> ) -> Result<C::Fruit>

Same as search(...) but multithreaded.

The current implementation is rather naive : multithreading is by splitting search into as many task as there are segments.

It is powerless at making search faster if your index consists in one large segment.

Also, keep in my multithreading a single query on several threads will not improve your throughput. It can actually hurt it. It will however, decrease the average response time.

source

pub fn space_usage(&self) -> Result<SearcherSpaceUsage>

Summarize total space usage of this searcher.

Trait Implementations§

source§

impl Bm25StatisticsProvider for Searcher

source§

fn total_num_tokens(&self, field: Field) -> Result<u64>

The total number of tokens in a given field across all documents in the index.
source§

fn total_num_docs(&self) -> Result<u64>

The total number of documents in the index.
source§

fn doc_freq(&self, term: &Term) -> Result<u64>

The number of documents containing the given term.
source§

impl Clone for Searcher

source§

fn clone(&self) -> Searcher

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Searcher

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Arc<SearcherInner>> for Searcher

source§

fn from(inner: Arc<SearcherInner>) -> Self

Converts to this type from the input type.

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<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<T> Fruit for T
where T: Send + Downcast,