[][src]Struct tantivy::collector::MultiCollector

pub struct MultiCollector<'a> { /* fields omitted */ }

Multicollector makes it possible to collect on more than one collector. It should only be used for use cases where the Collector types is unknown at compile time.

If the type of the collectors is known, you can just group yours collectors in a tuple. See the Combining several collectors section of the collector documentation.

#[macro_use]
extern crate tantivy;
use tantivy::schema::{Schema, TEXT};
use tantivy::{Index, Result};
use tantivy::collector::{Count, TopDocs, MultiCollector};
use tantivy::query::QueryParser;

fn example() -> Result<()> {
    let mut schema_builder = Schema::builder();
    let title = schema_builder.add_text_field("title", TEXT);
    let schema = schema_builder.build();
    let index = Index::create_in_ram(schema);
    {
        let mut index_writer = index.writer(3_000_000)?;
        index_writer.add_document(doc!(
            title => "The Name of the Wind",
        ));
        index_writer.add_document(doc!(
            title => "The Diary of Muadib",
        ));
        index_writer.add_document(doc!(
            title => "A Dairy Cow",
        ));
        index_writer.add_document(doc!(
            title => "The Diary of a Young Girl",
        ));
        index_writer.commit().unwrap();
    }

    let reader = index.reader()?;
    let searcher = reader.searcher();

    let mut collectors = MultiCollector::new();
    let top_docs_handle = collectors.add_collector(TopDocs::with_limit(2));
    let count_handle = collectors.add_collector(Count);
    let query_parser = QueryParser::for_index(&index, vec![title]);
    let query = query_parser.parse_query("diary")?;
    let mut multi_fruit = searcher.search(&query, &collectors)?;

    let count = count_handle.extract(&mut multi_fruit);
    let top_docs = top_docs_handle.extract(&mut multi_fruit);


    Ok(())
}

Methods

impl<'a> MultiCollector<'a>[src]

pub fn new() -> Self[src]

Create a new MultiCollector

pub fn add_collector<'b: 'a, TCollector: Collector + 'b>(
    &mut self,
    collector: TCollector
) -> FruitHandle<TCollector::Fruit>
[src]

Add a new collector to our MultiCollector.

Trait Implementations

impl<'a> Collector for MultiCollector<'a>[src]

type Fruit = MultiFruit

Fruit is the type for the result of our collection. e.g. usize for the Count collector. Read more

type Child = MultiCollectorChild

Type of the SegmentCollector associated to this collector.

impl<'a> Default for MultiCollector<'a>[src]

Auto Trait Implementations

impl<'a> !Send for MultiCollector<'a>

impl<'a> Sync for MultiCollector<'a>

impl<'a> Unpin for MultiCollector<'a>

impl<'a> !UnwindSafe for MultiCollector<'a>

impl<'a> !RefUnwindSafe for MultiCollector<'a>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T[src]

impl<T> Downcast for T where
    T: Any
[src]