Skip to content

Commit 2978105

Browse files
committed
Add Outcome::Ranked for new style search.
Issue #3
1 parent f718988 commit 2978105

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/outcome.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ impl Outcome {
3636
false => Outcome::NotFound { search },
3737
}
3838
}
39-
Expected::Ranked { key, min_rank } => todo!(),
39+
Expected::Ranked { key, min_rank } => {
40+
let search = CategorySearch::new_from_new_style(key, &search_results);
41+
let rank = Rank::new(*min_rank, search.rank());
42+
Outcome::Ranked { search, rank }
43+
}
4044
},
4145
},
4246
},
@@ -233,6 +237,35 @@ mod tests {
233237
);
234238
}
235239

240+
#[test]
241+
fn outcome_is_ranked_when_something_expected_and_is_in_results() {
242+
let expected = Expected::Ranked {
243+
key: SearchResultKey::Suttaplex {
244+
uid: SuttaplexUid::from("mn1"),
245+
},
246+
min_rank: 1,
247+
};
248+
249+
let search_results = Outcome::new_style_results(
250+
&Some(expected.clone()),
251+
Ok(String::from(SUTTAPLEX_MN1_JSON)),
252+
);
253+
254+
assert_eq!(
255+
Outcome::new_with_new_style_results(&Some(expected), search_results),
256+
Outcome::Ranked {
257+
search: CategorySearch::Suttaplex {
258+
search_for: SuttaplexUid::from("mn1"),
259+
in_results: vec![SuttaplexUid::from("mn1")],
260+
},
261+
rank: Rank::Sufficient {
262+
minimum: 1,
263+
actual: 1
264+
},
265+
}
266+
)
267+
}
268+
236269
#[test]
237270
fn new_outcome_is_success_when_nothing_expected() {
238271
let search_results = SearchResultsOldStyle {

suite_examples/examples.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[settings]
2-
endpoint = "http://localhost/api/search/instant"
3-
delay = 10
2+
endpoint = "https://suttacentral.net/api/search/instant"
3+
delay = 1000
44

55
[defaults]
66
limit = 10

0 commit comments

Comments
 (0)