atagen

macltok

public
Star0
Watch0
aced11e80b47de7a887296b10eedff310df5360f
3
ssh://brewery@pls.lobotomise.me:33/atagen/macltok.git
src/search_model.rsRust135 lines4.1 KB
1
use ruma::{OwnedEventId, OwnedRoomId};
2
#[cfg(feature = "serde")]
3
use serde::{Deserialize, Serialize};
4
5
use crate::TimelineEvent;
6
7
#[derive(Clone, Debug, Eq, PartialEq)]
8
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9
#[non_exhaustive]
10
pub enum SearchScope {
11
    Room(OwnedRoomId),
12
    /// a space's rooms, resolved by the host
13
    Rooms(Vec<OwnedRoomId>),
14
    /// every joined room
15
    All,
16
}
17
18
#[derive(Clone, Debug, Eq, PartialEq)]
19
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
20
#[non_exhaustive]
21
pub enum SearchCommand {
22
    /// opens a search that owns the media of every hit it hands out. at most 8 stay open,
23
    /// opening another closes the oldest. words must all match, `"quoted phrases"` match
24
    /// in order and `-word` excludes, newest first
25
    Search {
26
        query: String,
27
        scope: SearchScope,
28
        limit: u16,
29
    },
30
    /// `cursor` is the previous page's `next_cursor`
31
    More {
32
        search_id: String,
33
        cursor: String,
34
        limit: u16,
35
    },
36
    /// frees the search's media. its hits' media ids stop resolving
37
    Close {
38
        search_id: String,
39
    },
40
    Coverage(SearchScope),
41
}
42
43
/// a search's media stay resolvable until it closes, and past `EngineConfig::max_context_media`
44
/// its least recently used are dropped
45
#[derive(Clone, Debug, Eq, PartialEq)]
46
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
47
pub struct SearchSession {
48
    pub search_id: String,
49
    pub page: SearchPage,
50
}
51
52
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
53
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54
pub enum SearchCloseReason {
55
    /// opening a ninth search closed the oldest
56
    Evicted,
57
}
58
59
#[derive(Clone, Debug, Eq, PartialEq)]
60
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
61
pub struct SearchPage {
62
    pub hits: Vec<SearchHit>,
63
    /// `None` once there's nothing older that matches
64
    pub next_cursor: Option<String>,
65
    pub coverage: SearchCoverage,
66
}
67
68
#[derive(Clone, Debug, Eq, PartialEq)]
69
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
70
pub struct SearchHit {
71
    pub room_id: OwnedRoomId,
72
    pub event_id: OwnedEventId,
73
    pub timestamp_ms: u64,
74
    /// as event context shows it, with the latest edit applied
75
    pub event: TimelineEvent,
76
    /// utf-8 byte ranges of matched words in the content's text, the message body, a
77
    /// sticker's body or a poll's question
78
    pub matches: Vec<SearchMatch>,
79
}
80
81
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
82
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
83
pub struct SearchMatch {
84
    pub start: u32,
85
    pub end: u32,
86
}
87
88
#[derive(Clone, Debug, Eq, PartialEq)]
89
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
90
pub struct SearchCoverage {
91
    pub rooms: Vec<RoomSearchCoverage>,
92
    /// false when the index lives in memory and starts over with the next engine
93
    pub persistent: bool,
94
    /// why it lives in memory, `None` exactly when `persistent`
95
    pub in_memory: Option<SearchInMemory>,
96
    /// messages in scope that couldn't be decrypted yet, so can't be found yet
97
    pub undecrypted: usize,
98
}
99
100
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
101
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
102
pub enum SearchInMemory {
103
    /// the engine was built without a store, `Engine::from_client` or no store feature
104
    NoStore,
105
    OpenFailed,
106
    ReadFailed,
107
    /// five commits in a row failed, so this engine stopped trying
108
    CommitFailed,
109
}
110
111
#[derive(Clone, Debug, Eq, PartialEq)]
112
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
113
pub struct RoomSearchCoverage {
114
    pub room_id: OwnedRoomId,
115
    pub oldest_indexed_ms: Option<u64>,
116
    pub newest_indexed_ms: Option<u64>,
117
    /// backfill walked back to the oldest event the server would hand over
118
    pub start_reached: bool,
119
    pub backfill: SearchBackfill,
120
}
121
122
#[derive(Clone, Debug, Eq, PartialEq)]
123
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
124
pub enum SearchBackfill {
125
    Waiting,
126
    Running,
127
    /// this engine's page budget for the room is spent, the next one carries on
128
    Paused,
129
    Complete,
130
    Disabled,
131
    Failed {
132
        message: String,
133
        retry_at_ms: u64,
134
    },
135
}