Make implicit path queries explicit and simplify their handling

This commit is contained in:
Šarūnas Nejus 2022-05-31 21:51:47 +01:00
parent 988bf2672c
commit d68ed1adca
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
3 changed files with 7 additions and 19 deletions

View file

@ -1382,7 +1382,7 @@ def parse_query_parts(parts, model_cls):
`Query` and `Sort` they represent.
Like `dbcore.parse_sorted_query`, with beets query prefixes and
special path query detection.
ensuring that implicit path queries are made explicit with 'path::<query>'
"""
# Get query types and their prefix characters.
prefixes = {
@ -1394,28 +1394,14 @@ def parse_query_parts(parts, model_cls):
# Special-case path-like queries, which are non-field queries
# containing path separators (/).
path_parts = []
non_path_parts = []
for s in parts:
if PathQuery.is_path_query(s):
path_parts.append(s)
else:
non_path_parts.append(s)
parts = [f"path::{s}" if PathQuery.is_path_query(s) else s for s in parts]
case_insensitive = beets.config['sort_case_insensitive'].get(bool)
query, sort = dbcore.parse_sorted_query(
model_cls, non_path_parts, prefixes, case_insensitive
return dbcore.parse_sorted_query(
model_cls, parts, prefixes, case_insensitive
)
# Add path queries to aggregate query.
# Match field / flexattr depending on whether the model has the path field
fast_path_query = 'path' in model_cls._fields
query.subqueries += [PathQuery('path', s, fast_path_query)
for s in path_parts]
return query, sort
def parse_query_string(s, model_cls):
"""Given a beets query string, return the `Query` and `Sort` they

View file

@ -28,6 +28,9 @@ New features:
Bug fixes:
* Fix implicit paths OR queries (e.g. ``beet list /path/ , /other-path/``)
which have previously been returning the entire library.
:bug:`1865`
* The Discogs release ID is now populated correctly to the discogs_albumid
field again (it was no longer working after Discogs changed their release URL
format).

View file

@ -529,7 +529,6 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
results = self.lib.albums(q)
self.assert_albums_matched(results, ['path album'])
@unittest.skip('unfixed (#1865)')
def test_path_query_in_or_query(self):
q = '/a/b , /a/b'
results = self.lib.items(q)