From 72fe6f30071f3c131906cc6d4a2d2d54ec524d96 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 28 Mar 2023 21:30:03 +0300 Subject: [PATCH] Replaced fuzzy search with exact string start match --- README.md | 2 +- gnome-pass-search-provider.py | 22 ++++------------------ gnome-pass-search-provider.spec | 2 -- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0b4177d..b9340c4 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ dnf install gnome-pass-search-provider ## Manual -Ensure that python>=3.7 as well as the dbus, gobject and thefuzz (formerly fuzzywuzzy, might still be packaged under that name in your distribution) Python modules are installed. They should all be packaged under python-name or python3-name depending on your distribution. +Ensure that python>=3.7 as well as the dbus and gobject Python modules are installed. They should all be packaged under python-name or python3-name depending on your distribution. Clone this repository and run the installation script as root: ``` diff --git a/gnome-pass-search-provider.py b/gnome-pass-search-provider.py index 95f3a5b..4ccbcd5 100755 --- a/gnome-pass-search-provider.py +++ b/gnome-pass-search-provider.py @@ -32,12 +32,6 @@ from os.path import join as path_join import dbus.service from dbus.mainloop.glib import DBusGMainLoop -try: - from thefuzz import fuzz - from thefuzz import process -except ModuleNotFoundError: - from fuzzywuzzy import fuzz - from fuzzywuzzy import process from gi.repository import GLib # Convenience shorthand for declaring dbus interface methods. @@ -116,12 +110,8 @@ class SearchPassService(dbus.service.Object): [self.password_executable, "list"], universal_newlines=True ).split("\n")[:-1] - results = [ - e[0] - for e in process.extract( - name, password_list, limit=5, scorer=fuzz.partial_ratio - ) - ] + results = list(filter(lambda x: x.startswith(name), password_list))[:5] + if field is not None: results = [f":{field} {r}" for r in results] return results @@ -149,12 +139,8 @@ class SearchPassService(dbus.service.Object): path = path_join(dir_path, filename)[:-4] password_list.append(path) - results = [ - e[0] - for e in process.extract( - name, password_list, limit=5, scorer=fuzz.partial_ratio - ) - ] + results = list(filter(lambda x: x.startswith(name), password_list))[:5] + if field == "otp": results = [f"otp {r}" for r in results] elif field is not None: diff --git a/gnome-pass-search-provider.spec b/gnome-pass-search-provider.spec index e70828d..f10140a 100644 --- a/gnome-pass-search-provider.spec +++ b/gnome-pass-search-provider.spec @@ -9,8 +9,6 @@ Requires: gnome-shell Requires: pass Requires: python3-gobject Requires: python3-dbus -Requires: python3-fuzzywuzzy -Requires: python3-Levenshtein BuildRoot: %{_tmppath}/%{name}-%{version}-build %global debug_package %{nil}