nodedb_types/sync/wire/fts.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! FTS index/delete sync messages (client → server / server → client).
4//!
5//! `FtsIndexMsg` carries one document's text content from a Lite client to
6//! Origin for full-text indexing. `FtsDeleteMsg` removes a document from
7//! Origin's inverted index.
8//!
9//! Wire opcodes:
10//! - `0xA6` — `FtsIndex` (Lite → Origin)
11//! - `0xA7` — `FtsIndexAck` (Origin → Lite)
12//! - `0xA8` — `FtsDelete` (Lite → Origin)
13//! - `0xA9` — `FtsDeleteAck` (Origin → Lite)
14
15use serde::{Deserialize, Serialize};
16
17/// FTS index request (Lite → Origin, 0xA6).
18///
19/// Requests that Origin index the concatenated text of a document into its
20/// inverted BM25 index. Origin allocates a surrogate for `(collection, doc_id)`
21/// and calls `InvertedIndex::index_document` on the Data Plane.
22#[derive(
23 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
24)]
25pub struct FtsIndexMsg {
26 /// Lite instance ID (for routing and dedup).
27 pub lite_id: String,
28 /// Target collection name.
29 pub collection: String,
30 /// External document identifier.
31 pub doc_id: String,
32 /// Concatenated text to index (all string fields joined by space).
33 pub text: String,
34 /// Monotonic batch ID (Lite-assigned, per-document). Used for ACK correlation.
35 pub batch_id: u64,
36}
37
38/// FTS index acknowledgment (Origin → Lite, 0xA7).
39#[derive(
40 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
41)]
42pub struct FtsIndexAckMsg {
43 /// Collection acknowledged.
44 pub collection: String,
45 /// Document ID from the originating `FtsIndexMsg`.
46 pub doc_id: String,
47 /// Batch ID from the originating `FtsIndexMsg`.
48 pub batch_id: u64,
49 /// `true` if the document was successfully indexed on Origin.
50 pub accepted: bool,
51 /// Rejection detail when `accepted == false`.
52 #[serde(default)]
53 pub reject_reason: Option<String>,
54}
55
56/// FTS delete request (Lite → Origin, 0xA8).
57///
58/// Removes the document identified by `doc_id` from Origin's inverted index.
59#[derive(
60 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
61)]
62pub struct FtsDeleteMsg {
63 /// Lite instance ID.
64 pub lite_id: String,
65 /// Target collection name.
66 pub collection: String,
67 /// External document identifier to remove.
68 pub doc_id: String,
69 /// Monotonic batch ID for ACK correlation.
70 pub batch_id: u64,
71}
72
73/// FTS delete acknowledgment (Origin → Lite, 0xA9).
74#[derive(
75 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
76)]
77pub struct FtsDeleteAckMsg {
78 /// Collection acknowledged.
79 pub collection: String,
80 /// Document ID from the originating `FtsDeleteMsg`.
81 pub doc_id: String,
82 /// Batch ID from the originating `FtsDeleteMsg`.
83 pub batch_id: u64,
84 /// `true` if the document was successfully removed from Origin's index.
85 pub accepted: bool,
86 /// Rejection detail when `accepted == false`.
87 #[serde(default)]
88 pub reject_reason: Option<String>,
89}