Also perform bareasc queries in SQL

This commit is contained in:
Šarūnas Nejus 2023-04-08 05:30:32 +01:00
parent 0f1b5d6f7c
commit b5b1afbfff
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
3 changed files with 12 additions and 0 deletions

View file

@ -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

View file

@ -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."""

View file

@ -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`