mirror of
				https://github.com/wting/autojump
				synced 2025-06-13 12:54:07 +00:00 
			
		
		
		
	more clever fuzzy match
This commit is contained in:
		
							parent
							
								
									6a529f4f92
								
							
						
					
					
						commit
						547cba8bb6
					
				| @ -87,6 +87,17 @@ def match_consecutive(needles, haystack, ignore_case=False): | |||||||
|     ) |     ) | ||||||
|     return ifilter(found, haystack) |     return ifilter(found, haystack) | ||||||
| 
 | 
 | ||||||
|  | def percent_matcher(needles, path, ignore_case=False): | ||||||
|  |     percent = 0.0 | ||||||
|  |     source = path | ||||||
|  |     if ignore_case: | ||||||
|  |         source = source.lower() | ||||||
|  |     for i in needles: | ||||||
|  |         p = i | ||||||
|  |         if ignore_case: | ||||||
|  |             p = i.lower() | ||||||
|  |         percent += SequenceMatcher(p, source).ratio() | ||||||
|  |     return percent | ||||||
| 
 | 
 | ||||||
| def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6): | def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6): | ||||||
|     """ |     """ | ||||||
| @ -113,17 +124,7 @@ def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6): | |||||||
|     This is a weak heuristic and used as a last resort to find matches. |     This is a weak heuristic and used as a last resort to find matches. | ||||||
|     """ |     """ | ||||||
|     end_dir = lambda path: last(os.path.split(path)) |     end_dir = lambda path: last(os.path.split(path)) | ||||||
|     if ignore_case: |     match_percent = lambda entry: percent_matcher(needles, entry.path,\ | ||||||
|         needle = last(needles).lower() |         ignore_case) | ||||||
|         match_percent = lambda entry: SequenceMatcher( |  | ||||||
|             a=needle, |  | ||||||
|             b=end_dir(entry.path.lower()), |  | ||||||
|         ).ratio() |  | ||||||
|     else: |  | ||||||
|         needle = last(needles) |  | ||||||
|         match_percent = lambda entry: SequenceMatcher( |  | ||||||
|             a=needle, |  | ||||||
|             b=end_dir(entry.path), |  | ||||||
|         ).ratio() |  | ||||||
|     meets_threshold = lambda entry: match_percent(entry) >= threshold |     meets_threshold = lambda entry: match_percent(entry) >= threshold | ||||||
|     return ifilter(meets_threshold, haystack) |     return ifilter(meets_threshold, haystack) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user