caio.co/de/cantine

Remove DocId restriction from TopKProvider

Id
15cc861125f7af3ad493a17f6fa86758ee1fcc6c
Author
Caio
Commit time
2020-01-24T09:00:43+01:00

Modified tique/src/conditional_collector/custom_score.rs

@@ -15,7 +15,7
pub struct CustomScoreTopCollector<T, P, C, S>
where
T: PartialOrd,
- P: TopKProvider<T>,
+ P: TopKProvider<T, DocId>,
C: ConditionForSegment<T>,
{
limit: usize,
@@ -28,7 +28,7
impl<T, P, C, S> CustomScoreTopCollector<T, P, C, S>
where
T: PartialOrd,
- P: TopKProvider<T>,
+ P: TopKProvider<T, DocId>,
C: ConditionForSegment<T>,
{
pub fn new(limit: usize, condition_for_segment: C, scorer_for_segment: S) -> Self {
@@ -45,7 +45,7
impl<T, P, C, S> Collector for CustomScoreTopCollector<T, P, C, S>
where
T: 'static + PartialOrd + Copy + Send + Sync,
- P: 'static + Send + Sync + TopKProvider<T>,
+ P: 'static + Send + Sync + TopKProvider<T, DocId>,
C: Sync + ConditionForSegment<T>,
S: ScorerForSegment<T>,
{

Modified tique/src/conditional_collector/top_collector.rs

@@ -21,7 +21,7
impl<T, P, CF> TopCollector<T, P, CF>
where
T: PartialOrd,
- P: TopKProvider<T>,
+ P: TopKProvider<T, DocId>,
CF: ConditionForSegment<T>,
{
pub fn new(limit: usize, condition_for_segment: CF) -> Self {
@@ -41,7 +41,7
($type: ident, $err: literal) => {
impl<P, CF> TopCollector<$type, P, CF>
where
- P: 'static + Send + Sync + TopKProvider<$type>,
+ P: 'static + Send + Sync + TopKProvider<$type, DocId>,
CF: Send + Sync + ConditionForSegment<$type>,
{
pub fn top_fast_field(
@@ -68,7 +68,7

impl<P, CF> Collector for TopCollector<Score, P, CF>
where
- P: 'static + Send + Sync + TopKProvider<Score>,
+ P: 'static + Send + Sync + TopKProvider<Score, DocId>,
CF: Sync + ConditionForSegment<Score>,
{
type Fruit = CollectionResult<Score>;

Modified tique/src/conditional_collector/topk.rs

@@ -1,10 +1,8
use std::{
cmp::{Ordering, Reverse},
collections::BinaryHeap,
};

-use tantivy::DocId;
-
use super::CollectionResult;

pub trait TopK<T, D> {
@@ -14,8 +12,8
fn into_vec(self) -> Vec<(T, D)>;
}

-pub trait TopKProvider<T: PartialOrd> {
- type Child: TopK<T, DocId>;
+pub trait TopKProvider<T: PartialOrd, D: Ord> {
+ type Child: TopK<T, D>;

fn new_topk(limit: usize) -> Self::Child;
fn merge_many(limit: usize, items: Vec<CollectionResult<T>>) -> CollectionResult<T>;
@@ -23,8 +21,8

pub struct Ascending;

-impl<T: PartialOrd> TopKProvider<T> for Ascending {
- type Child = AscendingTopK<T, DocId>;
+impl<T: PartialOrd, D: Ord> TopKProvider<T, D> for Ascending {
+ type Child = AscendingTopK<T, D>;

fn new_topk(limit: usize) -> Self::Child {
AscendingTopK::new(limit)
@@ -37,8 +35,8

pub struct Descending;

-impl<T: PartialOrd> TopKProvider<T> for Descending {
- type Child = DescendingTopK<T, DocId>;
+impl<T: PartialOrd, D: Ord> TopKProvider<T, D> for Descending {
+ type Child = DescendingTopK<T, D>;

fn new_topk(limit: usize) -> Self::Child {
DescendingTopK {