Remove PartialOrd bound on compared values.

This commit is contained in:
Stu Hood
2025-12-03 21:55:24 -08:00
parent 794ff1ffc9
commit 0e7484cfa6
6 changed files with 29 additions and 16 deletions

View File

@@ -322,11 +322,12 @@ impl<TSegmentSortKeyComputer, TSegmentSortKey, TComparator> SegmentSortKeyComput
for SegmentSortKeyComputerWithComparator<TSegmentSortKeyComputer, TComparator> for SegmentSortKeyComputerWithComparator<TSegmentSortKeyComputer, TComparator>
where where
TSegmentSortKeyComputer: SegmentSortKeyComputer<SegmentSortKey = TSegmentSortKey>, TSegmentSortKeyComputer: SegmentSortKeyComputer<SegmentSortKey = TSegmentSortKey>,
TSegmentSortKey: PartialOrd + Clone + 'static + Sync + Send, TSegmentSortKey: Clone + 'static + Sync + Send,
TComparator: Comparator<TSegmentSortKey> + 'static + Sync + Send, TComparator: Comparator<TSegmentSortKey> + 'static + Sync + Send,
{ {
type SortKey = TSegmentSortKeyComputer::SortKey; type SortKey = TSegmentSortKeyComputer::SortKey;
type SegmentSortKey = TSegmentSortKey; type SegmentSortKey = TSegmentSortKey;
type SegmentComparator = TComparator;
fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey { fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey {
self.segment_sort_key_computer.segment_sort_key(doc, score) self.segment_sort_key_computer.segment_sort_key(doc, score)

View File

@@ -63,8 +63,8 @@ impl SortKeyComputer for SortBySimilarityScore {
impl SegmentSortKeyComputer for SortBySimilarityScore { impl SegmentSortKeyComputer for SortBySimilarityScore {
type SortKey = Score; type SortKey = Score;
type SegmentSortKey = Score; type SegmentSortKey = Score;
type SegmentComparator = NaturalComparator;
#[inline(always)] #[inline(always)]
fn segment_sort_key(&mut self, _doc: DocId, score: Score) -> Score { fn segment_sort_key(&mut self, _doc: DocId, score: Score) -> Score {

View File

@@ -34,9 +34,7 @@ impl<T: FastValue> SortByStaticFastValue<T> {
impl<T: FastValue> SortKeyComputer for SortByStaticFastValue<T> { impl<T: FastValue> SortKeyComputer for SortByStaticFastValue<T> {
type Child = SortByFastValueSegmentSortKeyComputer<T>; type Child = SortByFastValueSegmentSortKeyComputer<T>;
type SortKey = Option<T>; type SortKey = Option<T>;
type Comparator = NaturalComparator; type Comparator = NaturalComparator;
fn check_schema(&self, schema: &crate::schema::Schema) -> crate::Result<()> { fn check_schema(&self, schema: &crate::schema::Schema) -> crate::Result<()> {
@@ -84,8 +82,8 @@ pub struct SortByFastValueSegmentSortKeyComputer<T> {
impl<T: FastValue> SegmentSortKeyComputer for SortByFastValueSegmentSortKeyComputer<T> { impl<T: FastValue> SegmentSortKeyComputer for SortByFastValueSegmentSortKeyComputer<T> {
type SortKey = Option<T>; type SortKey = Option<T>;
type SegmentSortKey = Option<u64>; type SegmentSortKey = Option<u64>;
type SegmentComparator = NaturalComparator;
#[inline(always)] #[inline(always)]
fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> Self::SegmentSortKey { fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> Self::SegmentSortKey {

View File

@@ -30,9 +30,7 @@ impl SortByString {
impl SortKeyComputer for SortByString { impl SortKeyComputer for SortByString {
type SortKey = Option<String>; type SortKey = Option<String>;
type Child = ByStringColumnSegmentSortKeyComputer; type Child = ByStringColumnSegmentSortKeyComputer;
type Comparator = NaturalComparator; type Comparator = NaturalComparator;
fn segment_sort_key_computer( fn segment_sort_key_computer(
@@ -50,8 +48,8 @@ pub struct ByStringColumnSegmentSortKeyComputer {
impl SegmentSortKeyComputer for ByStringColumnSegmentSortKeyComputer { impl SegmentSortKeyComputer for ByStringColumnSegmentSortKeyComputer {
type SortKey = Option<String>; type SortKey = Option<String>;
type SegmentSortKey = Option<TermOrdinal>; type SegmentSortKey = Option<TermOrdinal>;
type SegmentComparator = NaturalComparator;
#[inline(always)] #[inline(always)]
fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> Option<TermOrdinal> { fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> Option<TermOrdinal> {

View File

@@ -12,13 +12,21 @@ use crate::{DocAddress, DocId, Result, Score, SegmentReader};
/// It is the segment local version of the [`SortKeyComputer`]. /// It is the segment local version of the [`SortKeyComputer`].
pub trait SegmentSortKeyComputer: 'static { pub trait SegmentSortKeyComputer: 'static {
/// The final score being emitted. /// The final score being emitted.
type SortKey: 'static + PartialOrd + Send + Sync + Clone; type SortKey: 'static + Send + Sync + Clone;
/// Sort key used by at the segment level by the `SegmentSortKeyComputer`. /// Sort key used by at the segment level by the `SegmentSortKeyComputer`.
/// ///
/// It is typically small like a `u64`, and is meant to be converted /// It is typically small like a `u64`, and is meant to be converted
/// to the final score at the end of the collection of the segment. /// to the final score at the end of the collection of the segment.
type SegmentSortKey: 'static + PartialOrd + Clone + Send + Sync + Clone; type SegmentSortKey: 'static + Clone + Send + Sync + Clone;
/// Comparator type.
type SegmentComparator: Comparator<Self::SegmentSortKey> + 'static;
/// Returns the segment sort key comparator.
fn segment_comparator(&self) -> Self::SegmentComparator {
Self::SegmentComparator::default()
}
/// Computes the sort key for the given document and score. /// Computes the sort key for the given document and score.
fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey; fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey;
@@ -47,7 +55,7 @@ pub trait SegmentSortKeyComputer: 'static {
left: &Self::SegmentSortKey, left: &Self::SegmentSortKey,
right: &Self::SegmentSortKey, right: &Self::SegmentSortKey,
) -> Ordering { ) -> Ordering {
NaturalComparator.compare(left, right) self.segment_comparator().compare(left, right)
} }
/// Implementing this method makes it possible to avoid computing /// Implementing this method makes it possible to avoid computing
@@ -81,7 +89,7 @@ pub trait SegmentSortKeyComputer: 'static {
/// the sort key at a segment scale. /// the sort key at a segment scale.
pub trait SortKeyComputer: Sync { pub trait SortKeyComputer: Sync {
/// The sort key type. /// The sort key type.
type SortKey: 'static + Send + Sync + PartialOrd + Clone + std::fmt::Debug; type SortKey: 'static + Send + Sync + Clone + std::fmt::Debug;
/// Type of the associated [`SegmentSortKeyComputer`]. /// Type of the associated [`SegmentSortKeyComputer`].
type Child: SegmentSortKeyComputer<SortKey = Self::SortKey>; type Child: SegmentSortKeyComputer<SortKey = Self::SortKey>;
/// Comparator type. /// Comparator type.
@@ -188,6 +196,11 @@ where
TailSegmentSortKeyComputer::SegmentSortKey, TailSegmentSortKeyComputer::SegmentSortKey,
); );
type SegmentComparator = (
HeadSegmentSortKeyComputer::SegmentComparator,
TailSegmentSortKeyComputer::SegmentComparator,
);
/// A SegmentSortKeyComputer maps to a SegmentSortKey, but it can also decide on /// A SegmentSortKeyComputer maps to a SegmentSortKey, but it can also decide on
/// its ordering. /// its ordering.
/// ///
@@ -269,11 +282,12 @@ impl<T, PreviousScore, NewScore> SegmentSortKeyComputer
for MappedSegmentSortKeyComputer<T, PreviousScore, NewScore> for MappedSegmentSortKeyComputer<T, PreviousScore, NewScore>
where where
T: SegmentSortKeyComputer<SortKey = PreviousScore>, T: SegmentSortKeyComputer<SortKey = PreviousScore>,
PreviousScore: 'static + Clone + Send + Sync + PartialOrd, PreviousScore: 'static + Clone + Send + Sync,
NewScore: 'static + Clone + Send + Sync + PartialOrd, NewScore: 'static + Clone + Send + Sync,
{ {
type SortKey = NewScore; type SortKey = NewScore;
type SegmentSortKey = T::SegmentSortKey; type SegmentSortKey = T::SegmentSortKey;
type SegmentComparator = T::SegmentComparator;
fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey { fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Self::SegmentSortKey {
self.sort_key_computer.segment_sort_key(doc, score) self.sort_key_computer.segment_sort_key(doc, score)
@@ -463,6 +477,7 @@ where
{ {
type SortKey = TSortKey; type SortKey = TSortKey;
type SegmentSortKey = TSortKey; type SegmentSortKey = TSortKey;
type SegmentComparator = NaturalComparator;
fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> TSortKey { fn segment_sort_key(&mut self, doc: DocId, _score: Score) -> TSortKey {
(self)(doc) (self)(doc)

View File

@@ -325,7 +325,7 @@ impl TopDocs {
sort_key_computer: impl SortKeyComputer<SortKey = TSortKey> + Send + 'static, sort_key_computer: impl SortKeyComputer<SortKey = TSortKey> + Send + 'static,
) -> impl Collector<Fruit = Vec<(TSortKey, DocAddress)>> ) -> impl Collector<Fruit = Vec<(TSortKey, DocAddress)>>
where where
TSortKey: 'static + Clone + Send + Sync + PartialOrd + std::fmt::Debug, TSortKey: 'static + Clone + Send + Sync + std::fmt::Debug,
{ {
TopBySortKeyCollector::new(sort_key_computer, self.doc_range()) TopBySortKeyCollector::new(sort_key_computer, self.doc_range())
} }
@@ -446,7 +446,7 @@ where
F: 'static + Send + Sync + Fn(&SegmentReader) -> TTweakScoreSortKeyFn, F: 'static + Send + Sync + Fn(&SegmentReader) -> TTweakScoreSortKeyFn,
TTweakScoreSortKeyFn: 'static + Fn(DocId, Score) -> TSortKey, TTweakScoreSortKeyFn: 'static + Fn(DocId, Score) -> TSortKey,
TweakScoreSegmentSortKeyComputer<TTweakScoreSortKeyFn>: TweakScoreSegmentSortKeyComputer<TTweakScoreSortKeyFn>:
SegmentSortKeyComputer<SortKey = TSortKey>, SegmentSortKeyComputer<SortKey = TSortKey, SegmentSortKey = TSortKey>,
TSortKey: 'static + PartialOrd + Clone + Send + Sync + std::fmt::Debug, TSortKey: 'static + PartialOrd + Clone + Send + Sync + std::fmt::Debug,
{ {
type SortKey = TSortKey; type SortKey = TSortKey;
@@ -481,6 +481,7 @@ where
{ {
type SortKey = TSortKey; type SortKey = TSortKey;
type SegmentSortKey = TSortKey; type SegmentSortKey = TSortKey;
type SegmentComparator = NaturalComparator;
fn segment_sort_key(&mut self, doc: DocId, score: Score) -> TSortKey { fn segment_sort_key(&mut self, doc: DocId, score: Score) -> TSortKey {
(self.sort_key_fn)(doc, score) (self.sort_key_fn)(doc, score)