mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-29 22:50:41 +00:00
Require Ord for ComparableDoc.
This commit is contained in:
@@ -12,7 +12,7 @@ pub trait Comparator<T>: 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<D: PartialOrd>(
|
||||
fn compare_doc<D: Ord>(
|
||||
&self,
|
||||
lhs: &ComparableDoc<T, D>,
|
||||
rhs: &ComparableDoc<T, D>,
|
||||
@@ -21,7 +21,7 @@ pub trait Comparator<T>: 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,15 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ComparableDoc<T, D> {
|
||||
/// 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<T>`.
|
||||
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<T: std::fmt::Debug, D: std::fmt::Debug> std::fmt::Debug for ComparableDoc<T, D> {
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user