@@ -176,39 +176,41 @@ pub fn init(config_dir: RString) -> State {
176
176
177
177
#[ get_matches]
178
178
pub fn get_matches ( input : RString , state : & State ) -> RVec < Match > {
179
- let matcher = fuzzy_matcher:: skim:: SkimMatcherV2 :: default ( ) . smart_case ( ) ;
179
+ let matcher = fuzzy_matcher:: skim:: SkimMatcherV2 :: default ( ) . ignore_case ( ) ;
180
180
let mut entries = state
181
181
. entries
182
182
. iter ( )
183
183
. filter_map ( |( entry, id) | {
184
- // Can be replaced by `Iterator::intersperse` once the API becomes stable.
185
- fn prefix_sep ( i : & Option < String > ) -> impl Iterator < Item = & str > + ' _ {
186
- i. as_deref ( )
187
- . map ( |s| [ " " , s] . into_iter ( ) )
188
- . into_iter ( )
189
- . flatten ( )
190
- }
191
-
192
- let app_names = ( [ & * entry. name ] . into_iter ( ) )
193
- . chain ( prefix_sep ( & entry. localized_name ) )
194
- . chain ( prefix_sep ( & entry. desc ) )
195
- . collect :: < String > ( ) ;
196
-
197
- let app_score = matcher. fuzzy_match ( & app_names, & input) . unwrap_or ( 0 ) ;
184
+ let name_score = matcher. fuzzy_match ( & entry. name , & input) . unwrap_or ( 0 ) . max (
185
+ matcher
186
+ . fuzzy_match ( & entry. localized_name ( ) , & input)
187
+ . unwrap_or ( 0 ) ,
188
+ ) ;
189
+ let desc_score = entry
190
+ . desc
191
+ . as_ref ( )
192
+ . and_then ( |desc| matcher. fuzzy_match ( desc, & input) )
193
+ . unwrap_or ( 0 ) ;
198
194
199
195
let keyword_score = ( entry. keywords . iter ( ) )
200
196
. chain ( entry. localized_keywords . iter ( ) . flat_map ( |k| k. iter ( ) ) )
201
- . map ( |keyword| matcher. fuzzy_match ( keyword, & input) . unwrap_or ( 0 ) )
202
- . sum :: < i64 > ( ) ;
197
+ . filter_map ( |keyword| matcher. fuzzy_match ( keyword, & input) )
198
+ . max ( )
199
+ . unwrap_or ( 0 ) ;
203
200
204
- let mut score = ( app_score * 25 + keyword_score) - entry. offset ;
201
+ let mut score = ( name_score * 10 + desc_score + keyword_score) - entry. offset ;
205
202
206
203
// prioritize actions
207
204
if entry. is_action {
208
205
score *= 2 ;
209
206
}
210
207
208
+ // Score cutoff
211
209
if score > 0 {
210
+ println ! (
211
+ "{} {name_score} {desc_score} {keyword_score} = {score}" ,
212
+ entry. name
213
+ ) ;
212
214
Some ( ( entry, * id, score) )
213
215
} else {
214
216
None
0 commit comments