2
2
from typing import List
3
3
4
4
SPACE_CHAR : str = ' '
5
- USER_SEARCH_PRECISION = 50
5
+ QUERY_SEARCH_PRECISION = {
6
+ 'Regular' : 50 ,
7
+ 'Low' : 20 ,
8
+ 'None' : 0
9
+ }
10
+ DEFAULT_QUERY_SEARCH_PRECISION = QUERY_SEARCH_PRECISION ['Regular' ]
6
11
7
12
"""
8
13
This is a python copy of Flow Launcher's string matcher.
14
19
class MatchData :
15
20
"""Match data"""
16
21
matched : bool
17
- score_cutoff : int = USER_SEARCH_PRECISION
22
+ score_cutoff : int
18
23
index_list : List [int ] = field (default_factory = list )
19
24
score : int = 0
20
25
21
26
22
- def string_matcher (query : str , text : str , ignore_case : bool = True ) -> MatchData :
27
+ def string_matcher (query : str , text : str , ignore_case : bool = True , query_search_precision : int = DEFAULT_QUERY_SEARCH_PRECISION ) -> MatchData :
23
28
"""Compare query to text"""
24
29
if not text or not query :
25
- return False
30
+ return MatchData ( False , query_search_precision )
26
31
27
32
query = query .strip ()
28
33
@@ -112,8 +117,8 @@ def string_matcher(query: str, text: str, ignore_case: bool = True) -> MatchData
112
117
if acronyms_matched > 0 and acronyms_matched == len (query ):
113
118
acronyms_score : int = acronyms_matched * 100 / acronyms_total_count
114
119
115
- if acronyms_score >= USER_SEARCH_PRECISION :
116
- return MatchData (True , USER_SEARCH_PRECISION , acronym_match_data , acronyms_score )
120
+ if acronyms_score >= query_search_precision :
121
+ return MatchData (True , query_search_precision , acronym_match_data , acronyms_score )
117
122
118
123
if all_query_substrings_matched :
119
124
@@ -123,9 +128,9 @@ def string_matcher(query: str, text: str, ignore_case: bool = True) -> MatchData
123
128
score = calculate_search_score (query , text , first_match_index - nearest_space_index - 1 ,
124
129
space_indices , last_match_index - first_match_index , all_substrings_contained_in_text )
125
130
126
- return MatchData (True , USER_SEARCH_PRECISION , index_list , score )
131
+ return MatchData (True , query_search_precision , index_list , score )
127
132
128
- return MatchData (False , USER_SEARCH_PRECISION )
133
+ return MatchData (False , query_search_precision )
129
134
130
135
131
136
def calculate_search_score (query : str , text : str , first_index : int , space_indices : List [int ], match_length : int , all_substrings_contained_in_text : bool ):
0 commit comments