pdg_rs/models/pdgmeta.rs
1use rusqlite::Row;
2
3use crate::{DataType, PdgId};
4
5/// Metadata row for a PDG identifier.
6#[derive(Clone, Debug)]
7pub struct PdgIdEntry {
8 /// Internal row ID from the bundled database.
9 pub id: isize,
10 /// PDG identifier.
11 pub pdgid: PdgId,
12 /// Parent PDG identifier, when this row belongs to another entry.
13 pub parent_pdgid: Option<PdgId>,
14 /// Human-readable PDG description.
15 pub description: String,
16 /// Decay or mode number for mode-specific rows.
17 pub mode_number: Option<isize>,
18 /// Data type represented by this identifier.
19 pub data_type: DataType,
20 /// Raw PDG flags associated with this row.
21 pub flags: String,
22 /// Edition year in which the row was added, when known.
23 pub year_added: Option<isize>,
24 /// Sort key used by the PDG tables.
25 pub sort: isize,
26}
27
28impl TryFrom<&Row<'_>> for PdgIdEntry {
29 type Error = rusqlite::Error;
30
31 fn try_from(row: &Row<'_>) -> Result<Self, Self::Error> {
32 Ok(Self {
33 id: row.get(0)?,
34 pdgid: row.get(1)?,
35 parent_pdgid: row.get(2)?,
36 description: row.get(3)?,
37 mode_number: row.get(4)?,
38 data_type: row.get(5)?,
39 flags: row.get(6)?,
40 year_added: row.get(7)?,
41 sort: row.get(8)?,
42 })
43 }
44}
45
46/// Source table for a [`TextSearchResult`].
47#[derive(Clone, Debug, PartialEq, Eq)]
48pub enum TextSearchSource {
49 /// The result matched a [`PdgIdEntry::description`].
50 Description,
51 /// The result matched a text block.
52 Text {
53 /// PDG text category code.
54 text_type: String,
55 /// Sort key for the matched text row.
56 sort: isize,
57 },
58 /// The result matched a footnote.
59 Footnote {
60 /// Footnote index for the matched footnote row.
61 index: isize,
62 },
63}
64
65/// A full-text search hit from [`crate::Pdg::search_text`].
66#[derive(Clone, Debug)]
67pub struct TextSearchResult {
68 /// PDG identifier for the matching row.
69 pub pdgid: PdgId,
70 /// Source table and location for the match.
71 pub source: TextSearchSource,
72 /// Full source text that matched the query.
73 pub text: String,
74 /// SQLite-generated snippet with matched terms bracketed.
75 pub snippet: String,
76 /// FTS rank score, where lower values are better matches.
77 pub score: f64,
78 /// Text-block representation when [`TextSearchSource::Text`] matched.
79 pub pdg_text: Option<PdgText>,
80}
81
82/// Free-form text block attached to a PDG identifier.
83#[derive(Clone, Debug)]
84pub struct PdgText {
85 /// PDG identifier that owns this text block.
86 pub pdgid: PdgId,
87 /// PDG text category code.
88 pub text_type: String,
89 /// Text content, when present in the database.
90 pub text: Option<String>,
91 /// Sort key used by the PDG tables.
92 pub sort: isize,
93}
94
95impl TryFrom<&Row<'_>> for PdgText {
96 type Error = rusqlite::Error;
97
98 fn try_from(row: &Row<'_>) -> Result<Self, Self::Error> {
99 Ok(Self {
100 pdgid: row.get(0)?,
101 text_type: row.get(1)?,
102 text: row.get(2)?,
103 sort: row.get(3)?,
104 })
105 }
106}
107
108/// Footnote attached to a PDG identifier or measurement.
109#[derive(Clone, Debug)]
110pub struct PdgFootnote {
111 /// PDG identifier for entry-level footnotes.
112 pub pdgid: Option<PdgId>,
113 /// Footnote index within the owning entry.
114 pub index: Option<isize>,
115 /// Footnote text, when present in the database.
116 pub text: Option<String>,
117 /// Whether the footnote is marked by a PDG change bar.
118 pub changebar: bool,
119}
120
121impl TryFrom<&Row<'_>> for PdgFootnote {
122 type Error = rusqlite::Error;
123
124 fn try_from(row: &Row<'_>) -> Result<Self, Self::Error> {
125 Ok(Self {
126 pdgid: row.get(0)?,
127 index: row.get(1)?,
128 text: row.get(2)?,
129 changebar: row.get(3)?,
130 })
131 }
132}