@@ -29,6 +29,13 @@ impl<T> AsRef<str> for MatcherCandidate<T> {
2929 }
3030}
3131
32+ #[ derive( Debug , Clone , Copy , PartialEq , Hash ) ]
33+ pub struct RecipeSearchQuery < ' a > {
34+ pub text : & ' a str ,
35+ pub locale : crate :: Locale ,
36+ pub job_id : Option < u8 > ,
37+ }
38+
3239fn preprocess_pattern ( pattern : & str ) -> String {
3340 pattern
3441 . chars ( )
@@ -37,17 +44,17 @@ fn preprocess_pattern(pattern: &str) -> String {
3744}
3845
3946pub type RecipeSearchEntry = ( u32 , & ' static crate :: Recipe ) ;
40- pub fn find_recipes (
41- search_string : & str ,
42- locale : crate :: Locale ,
43- ) -> impl Iterator < Item = RecipeSearchEntry > {
47+ pub fn find_recipes ( query : RecipeSearchQuery ) -> impl Iterator < Item = RecipeSearchEntry > {
4448 let pattern = Pattern :: parse (
45- & preprocess_pattern ( search_string ) ,
49+ & preprocess_pattern ( query . text ) ,
4650 CaseMatching :: Ignore ,
4751 Normalization :: Smart ,
4852 ) ;
4953 let entries = RECIPES . entries ( ) . filter_map ( |( recipe_id, recipe) | {
50- let item_name = get_raw_item_name ( recipe. item_id , locale) ?;
54+ let item_name = get_raw_item_name ( recipe. item_id , query. locale ) ?;
55+ if query. job_id . is_some_and ( |job_id| job_id != recipe. job_id ) {
56+ return None ;
57+ }
5158 Some ( MatcherCandidate {
5259 haystack : item_name,
5360 associated_data : ( recipe_id, recipe) ,
@@ -59,20 +66,28 @@ pub fn find_recipes(
5966 . map ( |( entry, _score) | entry. associated_data )
6067}
6168
69+ #[ derive( Debug , Clone , Copy , PartialEq , Hash ) ]
70+ pub struct StellarSearchQuery < ' a > {
71+ pub text : & ' a str ,
72+ pub locale : crate :: Locale ,
73+ pub job_id : Option < u8 > ,
74+ }
6275pub type StellarMissionSearchEntry = ( u32 , & ' static crate :: StellarMission ) ;
6376pub fn find_stellar_missions (
64- search_string : & str ,
65- locale : crate :: Locale ,
77+ query : StellarSearchQuery ,
6678) -> impl Iterator < Item = StellarMissionSearchEntry > {
6779 let pattern = Pattern :: parse (
68- & preprocess_pattern ( search_string ) ,
80+ & preprocess_pattern ( query . text ) ,
6981 CaseMatching :: Ignore ,
7082 Normalization :: Smart ,
7183 ) ;
7284 let mission_entries = STELLAR_MISSIONS
7385 . entries ( )
7486 . filter_map ( |( mission_id, mission) | {
75- let mission_name = get_stellar_mission_name ( mission_id, locale) ?;
87+ let mission_name = get_stellar_mission_name ( mission_id, query. locale ) ?;
88+ if query. job_id . is_some_and ( |job_id| job_id != mission. job_id ) {
89+ return None ;
90+ }
7691 Some ( MatcherCandidate {
7792 haystack : mission_name,
7893 associated_data : ( mission_id, mission) ,
@@ -83,7 +98,10 @@ pub fn find_stellar_missions(
8398 . flat_map ( |( mission_id, mission) | {
8499 mission. recipe_ids . iter ( ) . filter_map ( move |& recipe_id| {
85100 let recipe = RECIPES . get ( recipe_id) ?;
86- let item_name = get_raw_item_name ( recipe. item_id , locale) ?;
101+ let item_name = get_raw_item_name ( recipe. item_id , query. locale ) ?;
102+ if query. job_id . is_some_and ( |job_id| job_id != recipe. job_id ) {
103+ return None ;
104+ }
87105 Some ( MatcherCandidate {
88106 haystack : item_name,
89107 associated_data : ( mission_id, mission) ,
0 commit comments