Struct tantivy::collector::FilterCollector[][src]

pub struct FilterCollector<TCollector, TPredicate, TPredicateValue: FastValue> where
    TPredicate: 'static, 
{ /* fields omitted */ }

The FilterCollector collector filters docs using a u64 fast field value and a predicate. Only the documents for which the predicate returned "true" will be passed on to the next collector.

use tantivy::collector::{TopDocs, FilterCollector};
use tantivy::query::QueryParser;
use tantivy::schema::{Schema, TEXT, INDEXED, FAST};
use tantivy::{doc, DocAddress, Index};

let mut schema_builder = Schema::builder();
let title = schema_builder.add_text_field("title", TEXT);
let price = schema_builder.add_u64_field("price", INDEXED | FAST);
let schema = schema_builder.build();
let index = Index::create_in_ram(schema);

let mut index_writer = index.writer_with_num_threads(1, 10_000_000).unwrap();
index_writer.add_document(doc!(title => "The Name of the Wind", price => 30_200u64));
index_writer.add_document(doc!(title => "The Diary of Muadib", price => 29_240u64));
index_writer.add_document(doc!(title => "A Dairy Cow", price => 21_240u64));
index_writer.add_document(doc!(title => "The Diary of a Young Girl", price => 20_120u64));
assert!(index_writer.commit().is_ok());

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

let query_parser = QueryParser::for_index(&index, vec![title]);
let query = query_parser.parse_query("diary").unwrap();
let no_filter_collector = FilterCollector::new(price, &|value: u64| value > 20_120u64, TopDocs::with_limit(2));
let top_docs = searcher.search(&query, &no_filter_collector).unwrap();

assert_eq!(top_docs.len(), 1);
assert_eq!(top_docs[0].1, DocAddress(0, 1));

let filter_all_collector: FilterCollector<_, _, u64> = FilterCollector::new(price, &|value| value < 5u64, TopDocs::with_limit(2));
let filtered_top_docs = searcher.search(&query, &filter_all_collector).unwrap();

assert_eq!(filtered_top_docs.len(), 0);

Implementations

impl<TCollector, TPredicate, TPredicateValue: FastValue> FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: Collector + Send + Sync,
    TPredicate: Fn(TPredicateValue) -> bool + Send + Sync
[src]

pub fn new(
    field: Field,
    predicate: &'static TPredicate,
    collector: TCollector
) -> FilterCollector<TCollector, TPredicate, TPredicateValue>
[src]

Create a new FilterCollector.

Trait Implementations

impl<TCollector, TPredicate, TPredicateValue: FastValue> Collector for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: Collector + Send + Sync,
    TPredicate: 'static + Fn(TPredicateValue) -> bool + Send + Sync,
    TPredicateValue: 'static + FastValue
[src]

type Fruit = TCollector::Fruit

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

type Child = FilterSegmentCollector<TCollector::Child, TPredicate, TPredicateValue>

Type of the SegmentCollector associated to this collector.

Auto Trait Implementations

impl<TCollector, TPredicate, TPredicateValue> RefUnwindSafe for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: RefUnwindSafe,
    TPredicate: RefUnwindSafe,
    TPredicateValue: RefUnwindSafe
[src]

impl<TCollector, TPredicate, TPredicateValue> Send for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: Send,
    TPredicate: Sync
[src]

impl<TCollector, TPredicate, TPredicateValue> Sync for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: Sync,
    TPredicate: Sync
[src]

impl<TCollector, TPredicate, TPredicateValue> Unpin for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: Unpin,
    TPredicateValue: Unpin
[src]

impl<TCollector, TPredicate, TPredicateValue> UnwindSafe for FilterCollector<TCollector, TPredicate, TPredicateValue> where
    TCollector: UnwindSafe,
    TPredicate: RefUnwindSafe,
    TPredicateValue: UnwindSafe
[src]

Blanket Implementations

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

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

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

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

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

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

impl<T> Fruit for T where
    T: Send + Downcast
[src]

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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<V, T> VZip<V> for T where
    V: MultiLane<T>,