Skip to content

Commit b2f59af

Browse files
authored
Merge pull request #9 from indiv0/feat-add-statelist
Add `Statelist` struct
2 parents 463f9e1 + f93151b commit b2f59af

22 files changed

+1009
-584
lines changed

src/model.in.rs

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ pub struct Tips {
7474
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
7575
pub struct Tip {
7676
// Attributes
77-
pub count: u32,
78-
79-
pub tip: Vec<Tip>,
77+
pub text: String,
8078
}
8179

8280
/// A series of `DidYouMean` elements.
@@ -89,7 +87,15 @@ pub struct DidYouMeans {
8987
}
9088

9189
/// Provides a suggestion for a different query than the one provided.
92-
pub type DidYouMean = String;
90+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
91+
pub struct DidYouMean {
92+
// Attributes
93+
pub score: String, // TODO: find a way to put a floating point here.
94+
pub level: String,
95+
96+
#[serde(rename="$value")]
97+
pub value: String,
98+
}
9399

94100
/// Generated when a foreign language is detected in a query.
95101
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
@@ -142,35 +148,47 @@ pub struct Warnings {
142148
// Attributes
143149
pub count: u32,
144150

145-
pub warning: Vec<Warnings>,
146-
}
147-
148-
/// An enum representing all possible warning types.
149-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
150-
pub enum Warning {
151-
Spellcheck {
152-
// Attributes
153-
word: String,
154-
suggestion: String,
155-
text: String,
156-
},
157-
Delimeters {
158-
// Attributes
159-
text: String,
160-
},
161-
Translation {
162-
// Attributes
163-
phrase: String,
164-
trans: String,
165-
lang: String,
166-
text: String,
167-
},
168-
Reinterpret {
169-
// Attributes
170-
text: String,
171-
172-
alternative: Vec<Alternative>,
173-
},
151+
// TODO: find a way to merge these into an enum?
152+
pub spellcheck: Option<Vec<Spellcheck>>,
153+
pub delimeters: Option<Vec<Delimeters>>,
154+
pub translation: Option<Vec<Translation>>,
155+
pub reinterpret: Option<Vec<Reinterpret>>,
156+
}
157+
158+
/// Provides word and suggestion attributes as alternative spellings for a word
159+
/// in the query.
160+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
161+
pub struct Spellcheck {
162+
// Attributes
163+
word: String,
164+
suggestion: String,
165+
text: String,
166+
}
167+
168+
/// Represents a warning regarding mismatched delimiters in a query.
169+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
170+
pub struct Delimeters {
171+
// Attributes
172+
text: String,
173+
}
174+
175+
/// Represents a word or a phrase which was translated in the query.
176+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
177+
pub struct Translation {
178+
// Attributes
179+
phrase: String,
180+
trans: String,
181+
lang: String,
182+
text: String,
183+
}
184+
185+
/// Represents a warning that the query was reinterpred.
186+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
187+
pub struct Reinterpret {
188+
// Attributes
189+
text: String,
190+
191+
alternative: Vec<Alternative>,
174192
}
175193

176194
/// An alternative interpretation of an element in a query.
@@ -222,7 +240,7 @@ pub struct Pod {
222240
pub scanner: String,
223241
pub id: String,
224242
pub numsubpods: u32,
225-
//pub primary: Option<bool>, // TODO: unimplemented by `serde_xml`.
243+
pub primary: Option<bool>,
226244

227245
pub subpod: Vec<Subpod>,
228246
pub states: Option<States>,
@@ -240,6 +258,17 @@ pub struct States {
240258
// Attributes
241259
pub count: u32,
242260

261+
pub state: Vec<State>,
262+
pub statelist: Option<Vec<Statelist>>,
263+
}
264+
265+
/// A series of `State` attributes, combined into a list.
266+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
267+
pub struct Statelist {
268+
// Attributes
269+
pub count: u32,
270+
pub value: String,
271+
243272
pub state: Vec<State>,
244273
}
245274

0 commit comments

Comments
 (0)