Struct tantivy::collector::FilterCollector [−][src]
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]
TCollector: Collector + Send + Sync,
TPredicate: Fn(TPredicateValue) -> bool + Send + Sync,
pub fn new(
field: Field,
predicate: &'static TPredicate,
collector: TCollector
) -> FilterCollector<TCollector, TPredicate, TPredicateValue>
[src]
field: Field,
predicate: &'static TPredicate,
collector: TCollector
) -> FilterCollector<TCollector, TPredicate, TPredicateValue>
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]
TCollector: Collector + Send + Sync,
TPredicate: 'static + Fn(TPredicateValue) -> bool + Send + Sync,
TPredicateValue: 'static + FastValue,
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.
fn for_segment(
&self,
segment_local_id: u32,
segment_reader: &SegmentReader
) -> Result<FilterSegmentCollector<TCollector::Child, TPredicate, TPredicateValue>>
[src]
&self,
segment_local_id: u32,
segment_reader: &SegmentReader
) -> Result<FilterSegmentCollector<TCollector::Child, TPredicate, TPredicateValue>>
fn requires_scoring(&self) -> bool
[src]
fn merge_fruits(
&self,
segment_fruits: Vec<<TCollector::Child as SegmentCollector>::Fruit>
) -> Result<TCollector::Fruit>
[src]
&self,
segment_fruits: Vec<<TCollector::Child as SegmentCollector>::Fruit>
) -> Result<TCollector::Fruit>
fn collect_segment(
&self,
weight: &dyn Weight,
segment_ord: u32,
reader: &SegmentReader
) -> Result<<Self::Child as SegmentCollector>::Fruit>
[src]
&self,
weight: &dyn Weight,
segment_ord: u32,
reader: &SegmentReader
) -> Result<<Self::Child as SegmentCollector>::Fruit>
Auto Trait Implementations
impl<TCollector, TPredicate, TPredicateValue> RefUnwindSafe for FilterCollector<TCollector, TPredicate, TPredicateValue> where
TCollector: RefUnwindSafe,
TPredicate: RefUnwindSafe,
TPredicateValue: RefUnwindSafe,
[src]
TCollector: RefUnwindSafe,
TPredicate: RefUnwindSafe,
TPredicateValue: RefUnwindSafe,
impl<TCollector, TPredicate, TPredicateValue> Send for FilterCollector<TCollector, TPredicate, TPredicateValue> where
TCollector: Send,
TPredicate: Sync,
[src]
TCollector: Send,
TPredicate: Sync,
impl<TCollector, TPredicate, TPredicateValue> Sync for FilterCollector<TCollector, TPredicate, TPredicateValue> where
TCollector: Sync,
TPredicate: Sync,
[src]
TCollector: Sync,
TPredicate: Sync,
impl<TCollector, TPredicate, TPredicateValue> Unpin for FilterCollector<TCollector, TPredicate, TPredicateValue> where
TCollector: Unpin,
TPredicateValue: Unpin,
[src]
TCollector: Unpin,
TPredicateValue: Unpin,
impl<TCollector, TPredicate, TPredicateValue> UnwindSafe for FilterCollector<TCollector, TPredicate, TPredicateValue> where
TCollector: UnwindSafe,
TPredicate: RefUnwindSafe,
TPredicateValue: UnwindSafe,
[src]
TCollector: UnwindSafe,
TPredicate: RefUnwindSafe,
TPredicateValue: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
[src]
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T> Fruit for T where
T: Send + Downcast,
[src]
T: Send + Downcast,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,