Skip to content

Commit cc3d652

Browse files
committed
Create new module for general search and begin implementing.
Issue #3
1 parent 0729311 commit cc3d652

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/expected.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl TryFrom<&ExpectedDetails> for Expected {
7272
return Err(anyhow!("min-rank set but there is no expected result"));
7373
};
7474

75+
// TODO: remove unwrap()
7576
let key = details.search_key().unwrap();
7677

7778
match details.min_rank {

src/response.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod general;
2+
mod general_new;

src/response/general_new.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::identifiers::{DictionaryUrl, SuttaplexUid, TextUrl};
2+
use anyhow::{Error, Result};
3+
4+
#[derive(Clone, Debug, Default, PartialEq)]
5+
pub struct GeneralSearchResults {
6+
pub text: Vec<TextUrl>,
7+
pub dictionary: Vec<DictionaryUrl>,
8+
pub fuzzy_dictionary: Vec<DictionaryUrl>,
9+
pub suttaplex: Vec<SuttaplexUid>,
10+
}
11+
12+
impl TryFrom<&str> for GeneralSearchResults {
13+
type Error = Error;
14+
15+
fn try_from(_value: &str) -> Result<Self> {
16+
Ok(GeneralSearchResults::default())
17+
}
18+
}
19+
20+
#[cfg(test)]
21+
mod tests {
22+
use super::*;
23+
24+
#[test]
25+
fn single_text_result() {
26+
let json = r#"
27+
{
28+
"uid": "sa264",
29+
"lang": "en",
30+
"author_uid": "analayo",
31+
"url": "/sa264/en/analayo"
32+
}
33+
"#;
34+
35+
assert_eq!(
36+
GeneralSearchResults::try_from(json).unwrap(),
37+
GeneralSearchResults {
38+
text: vec![],
39+
..GeneralSearchResults::default()
40+
},
41+
)
42+
}
43+
}

0 commit comments

Comments
 (0)