@@ -58,7 +58,9 @@ pub struct MatchedLspItem {
58
58
59
59
#[ derive( Clone , Serialize , Deserialize , Hash ) ]
60
60
pub struct FuzzyOptions {
61
+ use_typo_resistance : bool ,
61
62
use_frecency : bool ,
63
+ use_proximity : bool ,
62
64
nearby_words : Option < Vec < String > > ,
63
65
min_score : u16 ,
64
66
max_items : u32 ,
@@ -68,14 +70,18 @@ pub struct FuzzyOptions {
68
70
impl FromLua < ' _ > for FuzzyOptions {
69
71
fn from_lua ( value : LuaValue < ' _ > , _lua : & ' _ Lua ) -> LuaResult < Self > {
70
72
if let Some ( tab) = value. as_table ( ) {
73
+ let use_typo_resistance: bool = tab. get ( "use_typo_resistance" ) . unwrap_or_default ( ) ;
71
74
let use_frecency: bool = tab. get ( "use_frecency" ) . unwrap_or_default ( ) ;
75
+ let use_proximity: bool = tab. get ( "use_proximity" ) . unwrap_or_default ( ) ;
72
76
let nearby_words: Option < Vec < String > > = tab. get ( "nearby_words" ) . ok ( ) ;
73
77
let min_score: u16 = tab. get ( "min_score" ) . unwrap_or_default ( ) ;
74
78
let max_items: u32 = tab. get ( "max_items" ) . unwrap_or_default ( ) ;
75
79
let sorts: Vec < String > = tab. get ( "sorts" ) . unwrap_or_default ( ) ;
76
80
77
81
Ok ( FuzzyOptions {
82
+ use_typo_resistance,
78
83
use_frecency,
84
+ use_proximity,
79
85
nearby_words,
80
86
min_score,
81
87
max_items,
@@ -102,17 +108,23 @@ pub fn fuzzy(
102
108
// Fuzzy match with fzrs
103
109
let haystack_labels = haystack
104
110
. iter ( )
105
- . map ( |s| s. label . as_str ( ) )
111
+ . map ( |s| {
112
+ if let Some ( filter_text) = & s. filter_text {
113
+ filter_text. as_str ( )
114
+ } else {
115
+ s. label . as_str ( )
116
+ }
117
+ } )
106
118
. collect :: < Vec < _ > > ( ) ;
107
119
let options = frizbee:: Options {
120
+ prefilter : !opts. use_typo_resistance ,
108
121
min_score : opts. min_score ,
109
122
stable_sort : false ,
110
123
..Default :: default ( )
111
124
} ;
112
125
let mut matches = frizbee:: match_list ( & needle, & haystack_labels, options) ;
113
126
114
127
// Sort by scores
115
- // TODO: boost exact matches
116
128
let match_scores = matches
117
129
. iter ( )
118
130
. map ( |mtch| {
@@ -121,23 +133,29 @@ pub fn fuzzy(
121
133
} else {
122
134
0
123
135
} ;
124
- let nearby_words_score = nearby_words
125
- . get ( & haystack[ mtch. index_in_haystack ] . label )
126
- . map ( |_| 2 )
127
- . unwrap_or ( 0 ) ;
136
+ let nearby_words_score = if opts. use_proximity {
137
+ nearby_words
138
+ . get ( & haystack[ mtch. index_in_haystack ] . label )
139
+ . map ( |_| 2 )
140
+ . unwrap_or ( 0 )
141
+ } else {
142
+ 0
143
+ } ;
128
144
let score_offset = haystack[ mtch. index_in_haystack ] . score_offset . unwrap_or ( 0 ) ;
129
145
130
146
( mtch. score as i32 ) + frecency_score + nearby_words_score + score_offset
131
147
} )
132
148
. collect :: < Vec < _ > > ( ) ;
133
149
134
150
// Find the highest score and filter out matches that are unreasonably lower than it
135
- let max_score = matches. iter ( ) . map ( |mtch| mtch. score ) . max ( ) . unwrap_or ( 0 ) ;
136
- let secondary_min_score = max_score. max ( 16 ) - 16 ;
137
- matches = matches
138
- . into_iter ( )
139
- . filter ( |mtch| mtch. score >= secondary_min_score)
140
- . collect :: < Vec < _ > > ( ) ;
151
+ if opts. use_typo_resistance {
152
+ let max_score = matches. iter ( ) . map ( |mtch| mtch. score ) . max ( ) . unwrap_or ( 0 ) ;
153
+ let secondary_min_score = max_score. max ( 16 ) - 16 ;
154
+ matches = matches
155
+ . into_iter ( )
156
+ . filter ( |mtch| mtch. score >= secondary_min_score)
157
+ . collect :: < Vec < _ > > ( ) ;
158
+ }
141
159
142
160
// Sort matches by sort criteria
143
161
for sort in opts. sorts . iter ( ) {
0 commit comments