1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::cmp::Ordering;
use crate::{Document, Embedding};

#[derive(Debug, Clone)]
pub struct DocumentMatch {
    pub score: f32,
    pub embedding_id: String,
    pub embedding: Embedding,
    pub embedded: Document,
}

impl DocumentMatch {
    pub fn new(score: f32, embedding_id: String, embedding: Embedding, embedded: Document) -> Self {
        DocumentMatch {
            score,
            embedding_id,
            embedding,
            embedded,
        }
    }
}

impl PartialOrd for DocumentMatch {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.score.partial_cmp(&other.score)
    }
}

impl PartialEq for DocumentMatch {
    fn eq(&self, other: &Self) -> bool {
        self.score == other.score
    }
}

impl Ord for DocumentMatch {
    fn cmp(&self, other: &Self) -> Ordering {
        self.score.partial_cmp(&other.score).unwrap_or(Ordering::Equal)
    }
}

impl Eq for DocumentMatch {
}