From 35c9eb6da2a71061a4e66fc42f3ad48be32e1a1d Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Tue, 16 Dec 2025 15:25:46 -0800 Subject: [PATCH] Require Ord for `ComparableDoc`. --- src/collector/sort_key/order.rs | 4 ++-- src/collector/top_collector.rs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/collector/sort_key/order.rs b/src/collector/sort_key/order.rs index 241fee619..22f59ad5a 100644 --- a/src/collector/sort_key/order.rs +++ b/src/collector/sort_key/order.rs @@ -12,7 +12,7 @@ pub trait Comparator: Send + Sync + std::fmt::Debug + Default { fn compare(&self, lhs: &T, rhs: &T) -> Ordering; /// Return the order between two ComparableDoc values. #[inline(always)] - fn compare_doc( + fn compare_doc( &self, lhs: &ComparableDoc, rhs: &ComparableDoc, @@ -21,7 +21,7 @@ pub trait Comparator: Send + Sync + std::fmt::Debug + Default { // In case of a tie on the feature, we always sort by descending `DocAddress` in order // to ensure a stable sorting of the documents. See the TopNComputer docs for more // information. - rhs.doc.partial_cmp(&lhs.doc).unwrap_or(Ordering::Equal) + rhs.doc.cmp(&lhs.doc) }) } } diff --git a/src/collector/top_collector.rs b/src/collector/top_collector.rs index 7650a36bc..1990b3837 100644 --- a/src/collector/top_collector.rs +++ b/src/collector/top_collector.rs @@ -6,17 +6,15 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct ComparableDoc { /// The feature of the document. In practice, this is - /// is any type that implements `PartialOrd`. + /// is a type which can be compared with a `Comparator`. pub sort_key: T, - /// The document address. In practice, this is any - /// type that implements `PartialOrd`, and is guaranteed - /// to be unique for each document. + /// The document address. In practice, this is either a `DocId` or `DocAddress`. pub doc: D, } impl std::fmt::Debug for ComparableDoc { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct(format!("ComparableDoc").as_str()) + f.debug_struct("ComparableDoc") .field("feature", &self.sort_key) .field("doc", &self.doc) .finish()