11//! Symbol search functionality
22
33use crate :: symbols:: Symbol ;
4- use fuzzy_matcher :: skim :: SkimMatcherV2 ;
5- use fuzzy_matcher :: FuzzyMatcher ;
4+ use nucleo_matcher :: pattern :: { Atom , CaseMatching , Normalization } ;
5+ use nucleo_matcher :: { Config , Matcher , Utf32Str } ;
66use std:: sync:: Arc ;
77
88pub struct SearchEngine {
9- matcher : SkimMatcherV2 ,
9+ matcher : Matcher ,
1010}
1111
1212#[ derive( Debug ) ]
@@ -17,8 +17,10 @@ pub struct SearchResult {
1717
1818impl SearchEngine {
1919 pub fn new ( ) -> Self {
20+ let mut config = Config :: DEFAULT ;
21+ config. normalize = true ;
2022 Self {
21- matcher : SkimMatcherV2 :: default ( ) . smart_case ( ) . use_cache ( true ) ,
23+ matcher : Matcher :: new ( config ) ,
2224 }
2325 }
2426
@@ -37,15 +39,23 @@ impl SearchEngine {
3739
3840 let start_time = std:: time:: Instant :: now ( ) ;
3941
42+ // Create the search pattern with smart case matching
43+ let pattern = Atom :: parse ( query, CaseMatching :: Smart , Normalization :: Smart ) ;
44+
45+ // Create a matcher instance for scoring
46+ let mut matcher = self . matcher . clone ( ) ;
47+
4048 // First pass: collect fuzzy match results
4149 let mut results: Vec < SearchResult > = symbols
4250 . iter ( )
4351 . filter_map ( |symbol| {
44- self . matcher
45- . fuzzy_match ( & symbol. name , query)
52+ let mut buf = Vec :: new ( ) ;
53+ let haystack = Utf32Str :: new ( & symbol. name , & mut buf) ;
54+ pattern
55+ . score ( haystack, & mut matcher)
4656 . map ( |score| SearchResult {
4757 symbol : Arc :: clone ( symbol) ,
48- score,
58+ score : score as i64 ,
4959 } )
5060 } )
5161 . collect ( ) ;
0 commit comments