Commit graph

54 commits

Author SHA1 Message Date
Šarūnas Nejus
5c81f94cf7
Move imports required for typing under the TYPE_CHECKING block 2024-12-10 06:10:04 +00:00
Šarūnas Nejus
161b0522bb
Update deprecated imports 2024-12-10 06:10:04 +00:00
Šarūnas Nejus
7ef1b61070
Replace Union types by PEP604 pipe character 2024-12-10 06:10:04 +00:00
Šarūnas Nejus
51f9dd229e
Use PEP585 lowercase collections typing annotations 2024-12-10 06:10:03 +00:00
Šarūnas Nejus
c216b636ac
Fixup: make common fields use fast queries
I surprisingly found that many queries for fields that exist in the
database are 'slow'. Querying items with 'month:0' used a slow query
while 'title:0' used a fast one.

I found the mistake in the logic: the field existence in the db check
was done *after* prepending the table name to the field. This meant that
the logic wrongly checked e.g. 'items.field' instead of 'field'.

This commit fixes the above and renames the variables for more clarity.
2024-08-11 21:35:28 +01:00
Šarūnas Nejus
bcc2826000
Make sure we can filter common fields 2024-06-21 15:05:29 +01:00
Šarūnas Nejus
981a61bd56
Add support for filtering relations 2024-06-21 15:05:29 +01:00
Šarūnas Nejus
2800a323a2
Revert "Make queries fast, filter all flexible attributes (#5240)"
This reverts commit 143b9202f3, reversing
changes made to 8508a57d77.
2024-06-19 21:51:44 +01:00
Šarūnas Nejus
6792a75c7e
Ensure that any field query uses the table name
In order to include the table name for fields in this query, use the
`field_query` method.

Since `AnyFieldQuery` is just an `OrQuery` under the hood, remove it and
construct `OrQuery` explicitly instead.
2024-06-16 15:28:46 +01:00
Šarūnas Nejus
9207b17d13
Enable querying related flexible attributes
Unify query creation logic from
- queryparse.py:construct_query_part,
- Model.field_query,
- DefaultTemplateFunctions._tmpl_unique

to a single implementation under `LibModel.field_query` class method.
This method should be used for query resolution for model (flex)fields.

Allow filtering item attributes in album queries and vice versa by
merging `flex_attrs` from Album and Item together as `all_flex_attrs`.
This field is only used for filtering and is discarded after.
2024-06-16 15:28:46 +01:00
Šarūnas Nejus
b0154d5cde
Fix querying fields present in both tables 2024-06-16 15:28:45 +01:00
Šarūnas Nejus
3347020c6c
Add support for filtering relations 2024-06-16 15:28:45 +01:00
Šarūnas Nejus
a57c164348
Remove NamedQuery
Remove 'NamedQuery' since it is not being used by any queries any more.

This simplifies query parsing logic in 'queryparse.py'. We know that
this logic can only receive 'FieldQuery' thus I adjusted types and
removed the logic that handles other cases.

Effectively, this means that the query parsing logic does not any more
care whether the query is named by the corresponding DB field. Instead,
queries like 'SingletonQuery' and 'PlaylistQuery' are responsible for
translating 'singleton' and 'playlist' to the underlying DB filters.
2024-04-30 22:20:36 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
wisp3rwind
8b11b3ef2e dbcore: improve/fix typing 2023-07-22 15:53:30 +02:00
wisp3rwind
09d2c87f29 typings: corrections for dbcore/queryparse
- Add NamedQuery abstract class to be able to express the expectation
  that a query should be such a query (and have a specific constructor
  signature) in construct_query_part
- slightly (and probably completely irrelevantly) improve Query.__hash__
- also, sprinkle some ABC/abstractmethod around to clarify things
2023-06-23 10:59:51 +02:00
Serene-Arc
3f4f559912 Remove unused import 2023-06-02 16:04:15 +10:00
Serene-Arc
eac46bf9dd Fix some typings 2023-06-02 15:15:43 +10:00
Serene-Arc
3f8afb9a45 Fix and mark errors 2023-06-02 15:15:43 +10:00
Serene-Arc
e29337d4e6 Add typing to queries modules 2023-06-02 15:14:16 +10:00
Andrew Rogl
d288f87290 pyupgrade dbcore dir 2021-08-25 18:48:26 +10:00
Jack Wilsdon
e10be98b66
Stop using beets.config['sort_case_insensitive'] in beets.dbcore 2019-04-27 15:44:56 +01:00
Adrian Sampson
d8e167637e Prototype support for named (pseudo-field) queries
As discussed here:
https://github.com/beetbox/beets/pull/3145#pullrequestreview-204523870

This would replace the need for #3149.
2019-02-17 13:41:05 -05:00
Adrian Sampson
bac8faad78 Resolve W605: invalid escape sequence
This came up in lots of regexes that weren't using "raw" literals.
2018-08-13 10:41:01 -04:00
Adrian Sampson
dd66ca51f9 Detail on example (#1794) 2016-01-04 22:08:27 -08:00
Adrian Sampson
d064f19129 Fix wrong word in docstring (#1794) 2016-01-04 18:49:14 -08:00
Adrian Sampson
a218da1414 A bunch of docs on query parsing (fix #1794) 2016-01-04 11:26:57 -08:00
Jack Wilsdon
12cd5306b7 Update copyright dates to 2016 2015-12-30 15:42:06 +00:00
Adrian Sampson
6cb8db3b2e Merge pull request #1728 from diego-plan9/notquery
Add boolean "not" query operator
2015-11-20 10:00:05 -08:00
Peter Kessen
3eb8008b11 added encoding as comment in files
added line like
# -*- coding: utf-8 -*-
to all files with correct license in header
2015-11-19 18:41:01 +01:00
Diego Moreda
40bfed756b Revise not query syntax, cleanup, modify docstring
* Revise the NotQuery syntax, replacing the '¬' character with '^'. Fix tests
to conform to this change, and cleanup the PARSE_QUERY_PART_REGEX.
* Modify parse_query_part() docstring to mention the negate parameter on the
returned tuple, and added an example.
2015-11-19 18:04:47 +01:00
Diego Moreda
0293504a24 Update negation query syntax, prefix always first
* Update the negation query sintax so that the negation prefix ("-" or "¬") is
always the first part of a query, instead of after the ":" separator.
* Modify queryparse, so that the detection of the negation is done inside
parse_query_part() (using the modified PARSE_QUERY_PART_REGEX, and returning
the negation flag) instead of construct_query_part.
* Revert the prefixes dict on beets.library to the original dict (only one item,
with the RegexpQuery prefix).
2015-11-18 16:59:50 +01:00
Diego Moreda
dd8b80e320 Make NotQuery subclass Query, update tests
* Modify NotQuery so it subclasses Query instead of MutableCollectionQuery.
* Update instances where NotQuery objects are created on tests and queryparse,
as NotQuery expects a single Query as a parameter to the constructor instead of
a list of Queries.
2015-11-18 14:54:20 +01:00
Diego Moreda
f2c8e9ff07 Add "not" query operator, initial draft
* Add support for user friendly "not" operator in queries without requiring to
use regular expressions, via adding NotQuery to beets.dbcore.query.
* Update the prefix list at library.parse_query_parts() and the query parsing
mechanisms in order to create a NotQuery when the prefix is found.
* Add two TestCases, NotQueryMatchTest as the negated version of MatchTest, and
the more generic NotQueryTest for testing the integration of the NotQuery with
the rest of the existing Query subclasses.
2015-11-16 21:36:42 +01:00
Adrian Sampson
f4a124e7e2 Fix #1605: parsing bare + and - in queries 2015-09-15 13:53:41 -07:00
Tom Jaspers
2ce38a254e Sort is case insensitive by default
Renamed "ignore_case" to more canonical "case_insensitive"
2015-04-18 10:25:28 +02:00
Tom Jaspers
18d262a59c Sort can ignore case if configured to do so
- Config option `sort_ignore_case`
- Default behavior was (and is) case sensitive
2015-04-17 14:24:56 +02:00
Tom Jaspers
b5ca50da46 Use comma as "or" operator for queries
Scan the query parts for commas (u',') and treat these as sub-AndQueries
that need to be wrapped in an OrQuery (if there are more than 1 of these)
2015-04-15 23:09:37 +02:00
Bruno Cauet
bcd57bd2b5 Test queries building sort management in smartplaylist
Slighly modify Sort parsing: avoid building MultiplSort() instances
comptised of a single sort, but return that sort instead, since it wraps
things with any gain.
2015-03-18 18:53:41 +01:00
Bruno Cauet
90b388b775 Use __future__ imports but unicode_literals everywhere
Include import of __future__ features division, absolute_imports and
print_function everywhere. Don't add unicode_literals yet for it is
harder to convert.

Goal is smoothing the transition to python 3.
2015-01-19 12:25:16 +01:00
Frederik “Freso” S. Olesen
4b1f0cbf48 Happy 2015. ;)
See 7a410f636b

Command used:

    git grep -l 'Copyright 201'|xargs sed -i -E 's/Copyright 201./Copyright 2015/'`
2015-01-08 21:37:09 +01:00
Adrian Sampson
f9c6dd6d67 Move SmartArtistSort to library (#953)
Models can now have a dict of special sort classes.
2014-09-15 19:43:22 -07:00
Adrian Sampson
e2b3fafefa Remove SortedQuery (#953)
This turned out to be less useful than I was hoping.
2014-09-15 18:39:49 -07:00
Adrian Sampson
0f37737168 dbcore: parse_sorted_query (#953) 2014-09-15 17:52:52 -07:00
Adrian Sampson
2b921b19fd NullSort instead of None
A more descriptive placeholder for "don't sort".
2014-09-13 20:38:31 -07:00
Adrian Sampson
369533d46f Remove special_sorts
These are not extensible anyway; we'll need another mechanism for that.
2014-09-13 19:47:20 -07:00
Adrian Sampson
4870d7e0fa Roll back fast flexible field sorts (#953)
Sad to see them go, but happy be rid of the SQL injection.
2014-09-13 17:16:12 -07:00
Adrian Sampson
bb4082fbfc Style cleanup in sorting 2014-09-12 20:58:25 -07:00
Pierre Rust
cd1dcf6969 Fix minor formatting and comments issues. 2014-07-02 13:05:33 +02:00
Pierre Rust
1d61088cfc Sort on computed field implementation.
Sort is implemented in python.
When combining sorts on fixed, flex and computed field, make as
much as possible in sql and finishes the job in python.
2014-06-15 22:32:25 +02:00