Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 32275bf

Browse files
committed
Use Flow Launcher score cutoff
1 parent 6374d87 commit 32275bf

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

flox/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ def app_settings(self):
238238
with open(os.path.join(self.appdata, 'Settings', 'Settings.json'), 'r') as f:
239239
return json.load(f)
240240

241+
@property
242+
def query_search_precision(self):
243+
return self.app_settings['QuerySearchPrecision']
244+
241245
@cached_property
242246
def user_keywords(self):
243247
return self.app_settings['PluginSettings']['Plugins'].get(self.id, {}).get('UserKeywords', [self.action_keyword])

flox/string_matcher.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
from typing import List
33

44
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']
611

712
"""
813
This is a python copy of Flow Launcher's string matcher.
@@ -14,15 +19,15 @@
1419
class MatchData:
1520
"""Match data"""
1621
matched: bool
17-
score_cutoff: int = USER_SEARCH_PRECISION
22+
score_cutoff: int
1823
index_list: List[int] = field(default_factory=list)
1924
score: int = 0
2025

2126

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:
2328
"""Compare query to text"""
2429
if not text or not query:
25-
return False
30+
return MatchData(False, query_search_precision)
2631

2732
query = query.strip()
2833

@@ -112,8 +117,8 @@ def string_matcher(query: str, text: str, ignore_case: bool = True) -> MatchData
112117
if acronyms_matched > 0 and acronyms_matched == len(query):
113118
acronyms_score: int = acronyms_matched * 100 / acronyms_total_count
114119

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)
117122

118123
if all_query_substrings_matched:
119124

@@ -123,9 +128,9 @@ def string_matcher(query: str, text: str, ignore_case: bool = True) -> MatchData
123128
score = calculate_search_score(query, text, first_match_index - nearest_space_index - 1,
124129
space_indices, last_match_index - first_match_index, all_substrings_contained_in_text)
125130

126-
return MatchData(True, USER_SEARCH_PRECISION, index_list, score)
131+
return MatchData(True, query_search_precision, index_list, score)
127132

128-
return MatchData(False, USER_SEARCH_PRECISION)
133+
return MatchData(False, query_search_precision)
129134

130135

131136
def calculate_search_score(query: str, text: str, first_index: int, space_indices: List[int], match_length: int, all_substrings_contained_in_text: bool):

flox/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.19.1
1+
0.19.2

0 commit comments

Comments
 (0)