New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New query parser with numeric expressions and query plugins #1799
Conversation
Exciting! Is it also possible to have two variables in one @-expression? E.g.: |
Numeric comparisons with more than one tag work, like Extensions using |
Okay thanks for clearing up. So, I could filter out However, these queries (conditions, exactly) won't work for column headers in browsers, right? |
Sorry for the delay.. On the pull request:
On the implementation/features: Why isn't it possible to implement the numeric expressions on top of the |
I figured this pull request would be fairly unexpected, but after writing it primarily for my own use I decided to make a pull request in case it's worth including in the main project. As for the implementation, the lexer parsed all If the loss of backwards compatibility with |
I see, thanks. I would hav epreferred if the numexp parsing was separate, but the new code looks readable/documented enough..
I don't think that's a big problem.. One problem I see is that spaces in tags no longer work and escaping them doesn't help. e.g. |
Oh, the tag parsing must have been overly restrictive. Tags containing spaces should now work properly. |
New query parser with numeric expressions and query plugins
|
Can you provide examples for the |
With the python expression query plugin:
With the saved search plugin:
With the conditional plugin:
None of these work unless the corresponding plugin is first enabled in the plugins menu. |
Thanks , enabled in the plugins was the missing bit... Note : @-queries appear valid (turn green) even if plugins aren't enabled. Not sure what can be done about it. |
By any chance, does the |
No, only filtering. |
This is a rewrite of the code for parsing queries. This allows numeric expressions such as "length + 8 seconds", "playcount * 2", and "(1-rating)*5 days" to be used on both the right and left side of numeric comparisons. Any numerical comparisons that parsed before should still work the same.
This expansion of numeric comparisons addresses issue #1492, and to some extent #198.
This also adds a "@(plugin)" syntax for plugins to extend queries with custom types of searches. This is backwards incompatible with some queries containing '@', however. Three query plugins are included: conditional queries, python expression queries, and including saved searches in queries.
The syntax for the query plugins:
@(if: condition query: then query: else query)
@(saved: some search name)
@(python: expression)
. Thes
variable is the song being matched.Implementation-wise, this parser parses through each character individually instead of having a separate lexer, which allows the numerical expressions to be much more easily parsed.
The interface of the quodlibet.query.Query class is identical to before, although the internal implementation has changed somewhat.
The following test cases have been added to cover the additions:
tests/test_query.py: TQuery_is_valid.test_extension
tests/test_query.py: TQuery_is_valid.test_numexpr
tests/test_query.py: TQuery.test_numexpr
tests/test_query.py: TQuery.test_numexpr_date
tests/test_query__match.py: TQueryMatch
tests/plugin/test_query.py: TQueryPlugins
The test case TNumericOp in tests/test_query__match.py was removed because it contained only tests pertaining to the previous parser implementation.
I've tried to be backwards compatible with the old parser wherever possible. As far as I can tell, the only exception to this is queries containing '@' (which is now a special character).
This does keep backwards compatibility with date expressions such as '2007-07-19' in numeric comparisons by interpreting them as dates if the comparison contains a 'date' tag and as subtraction otherwise.