Add docs for the remaining public items
- Id
- e440b6e613e746f6e43465a2dc9fad1fd31218df
- Author
- Caio
- Commit time
- 2020-01-27T11:21:29+01:00
Modified tique/src/conditional_collector/top_collector.rs
}
}
+/// The basic result type, containing the top selected items and
+/// additional metadata.
#[derive(Debug)]
pub struct CollectionResult<T> {
+ /// How many documents were seen. Analogous to the result of a
+ /// simple count collector.
pub total: usize,
+ /// How many of the documents we saw actually passed our
+ /// condition
pub visited: usize,
+ /// The top found items, as you would get from `tantivy::TopDocs`
pub items: Vec<(T, DocAddress)>,
}
impl<T> CollectionResult<T> {
+ /// Wether the same query that created this result would have
+ /// more results if we paginated (or increased the top-k limit)
pub fn has_next(&self) -> bool {
self.visited - self.items.len() > 0
}
Modified tique/src/conditional_collector/topk.rs
fn merge_many(limit: usize, items: Vec<CollectionResult<T>>) -> CollectionResult<T>;
}
+/// Marker to create a TopCollector in *ascending* order
pub struct Ascending;
impl<T: PartialOrd, D: Ord> TopKProvider<T, D> for Ascending {
}
}
+/// Marker to create a TopCollector in *descending* order
pub struct Descending;
impl<T: PartialOrd, D: Ord> TopKProvider<T, D> for Descending {
Modified tique/src/conditional_collector/traits.rs
use std::cmp::Ordering;
use tantivy::{DocAddress, DocId, SegmentLocalId, SegmentReader};
use super::topk::Scored;
+/// A trait that allows defining arbitrary conditions to be checked
+/// before considering a matching document for inclusion in the
+/// top results.
pub trait ConditionForSegment<T>: Clone {
type Type: CheckCondition<T>;
fn for_segment(&self, reader: &SegmentReader) -> Self::Type;
}
}
+/// The condition that gets checked before collection. In order for
+/// a document to appear in the results it must first return true
+/// for `check`.
pub trait CheckCondition<T>: 'static + Clone {
fn check(&self, segment_id: SegmentLocalId, doc_id: DocId, score: T, ascending: bool) -> bool;
}