MeiliSearch/milli/src/search/distinct/noop_distinct.rs

39 lines
916 B
Rust
Raw Normal View History

2021-04-14 12:00:45 +02:00
use roaring::{RoaringBitmap, bitmap::IntoIter};
use crate::DocumentId;
use super::{DocIter, Distinct};
2021-04-14 12:00:45 +02:00
/// A distinct implementer that does not perform any distinct, and simply returns an iterator to
/// the candidates.
pub struct NoopDistinct;
pub struct NoopDistinctIter {
2021-04-14 12:00:45 +02:00
candidates: IntoIter,
excluded: RoaringBitmap,
}
impl Iterator for NoopDistinctIter {
type Item = anyhow::Result<DocumentId>;
fn next(&mut self) -> Option<Self::Item> {
self.candidates.next().map(Result::Ok)
}
}
impl DocIter for NoopDistinctIter {
fn into_excluded(self) -> RoaringBitmap {
self.excluded
}
}
impl Distinct<'_> for NoopDistinct {
type Iter = NoopDistinctIter;
fn distinct(&mut self, candidates: RoaringBitmap, excluded: RoaringBitmap) -> Self::Iter {
NoopDistinctIter {
candidates: candidates.into_iter(),
excluded,
}
}
}