appGenericName, appComment and appExec to the fuzzysearch function

This commit is contained in:
Jesper 2024-06-12 12:19:05 +02:00
parent 2e0f503d08
commit a31731f127

View File

@ -763,20 +763,37 @@ class pluginclass(object):
return value
def fuzzy_application_search(self, search_text):
labels = [app["button"].appName for app in self.applicationList]
results = process.extract(search_text, labels, limit=len(labels))
shownList = []
keywords = self.strip_case_and_accents(search_text).split()
labels = [app["button"].appName for app in self.applicationList]
results = process.extract(search_text, labels, limit=len(labels))
first_button = True
first_button = True
for match in results:
if match[1] > 60: # Adjust the threshold as needed
for app in self.applicationList:
if app["button"].appName == match[0]:
self.applicationsBox.pack_start(app["button"], False, False, 0)
if first_button is True:
app["button"].grab_focus()
first_button = False
shownList.append(app["button"])
# Non-fuzzy results for appGenericName, appComment and appExec
# Again I should really make it a function or something
for app in self.applicationList:
for item in shownList:
if app["button"].desktopFile == item.desktopFile:
continue
for keyword in keywords:
if keyword != "" and (self.strip_case_and_accents(app["button"].appGenericName).find(keyword) != -1 or self.strip_case_and_accents(app["button"].appComment).find(keyword) != -1 or self.strip_case_and_accents(app["button"].appExec).find(keyword) != -1):
self.applicationsBox.pack_start(app["button"], False, False, 0)
if first_button is True:
app["button"].grab_focus()
first_button = False
shownList.append(app["button"])
for match in results:
if match[1] > 60: # Adjust the threshold as needed
for app in self.applicationList:
if app["button"].appName == match[0]:
self.applicationsBox.pack_start(app["button"], False, False, 0)
if first_button is True:
app["button"].grab_focus()
first_button = False
# TODO: Add appGenericName, appComment and appExec
def exact_application_search(self, search_text):
shownList = []
@ -795,6 +812,7 @@ class pluginclass(object):
app["button"].grab_focus()
first_button = False
shownList.append(app["button"])
# Add applications that match appGenericName, appComment or appExec
for app in self.applicationList:
for item in shownList:
@ -1747,4 +1765,4 @@ class pluginclass(object):
# print "=======>>> " + item.get_name() + " = top level"
# newApplicationsList.append({"entry": item, "category": ""})
return newApplicationsList
return newApplicationsList