diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 55c78c88d..94396f81b 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -23,6 +23,8 @@ import threading import sqlite3 import contextlib +from unidecode import unidecode + import beets from beets.util import functemplate from beets.util import py3_path @@ -995,6 +997,7 @@ class Database: return re.search(pattern, str(value)) is not None conn.create_function("regexp", 2, regexp) + conn.create_function("unidecode", 1, unidecode) def _close(self): """Close the all connections to the underlying SQLite database diff --git a/beetsplug/bareasc.py b/beetsplug/bareasc.py index 218369364..3343786f9 100644 --- a/beetsplug/bareasc.py +++ b/beetsplug/bareasc.py @@ -42,6 +42,14 @@ class BareascQuery(StringFieldQuery): val = unidecode(val) return pattern in val + def col_clause(self): + """Compare ascii version of the pattern.""" + clause = f"unidecode({self.field})" + if self.pattern.islower(): + clause = f"lower({clause})" + + return rf"{clause} LIKE ? ESCAPE '\'", [f"%{unidecode(self.pattern)}%"] + class BareascPlugin(BeetsPlugin): """Plugin to provide bare-ASCII option for beets matching.""" diff --git a/docs/changelog.rst b/docs/changelog.rst index f1cca7570..7a5ecdfe7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ New features: * --from-logfile now parses log files using a UTF-8 encoding in `beets/beets/ui/commands.py`. :bug:`4693` +* :doc:`/plugins/bareasc` lookups have been made faster * :ref:`list-cmd` lookups using the pattern operator `::` have been made faster * Added additional error handling for `spotify` plugin. :bug:`4686`