Skip to content
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

Support MPD 0.21 style filters #129

Merged
merged 10 commits into from
Jan 2, 2021
Merged

Support MPD 0.21 style filters #129

merged 10 commits into from
Jan 2, 2021

Conversation

iyefrat
Copy link
Contributor

@iyefrat iyefrat commented Dec 17, 2020

In version 0.21 MPD added a more expressive syntax for filters. This PR implements it in libmpd in a backwards compatible way by changing the Query type from

data Query = Query [Match]

to:

data Query = Query [Match] | Filter Expr

where Expr corrisponds to the newer syntax. This change is backwards compatible, both in the sense that it doesn't break existing Haskell code using libmpd (tests pass, vimus compiles), and that libmpd generates MPD 0.20 style filters for queries not created with the new combinators.

The new combinators are:

  • Tag /=? "value" for tag is not equal to "value"
  • Tag %? "value" for tag contains the string "value" as a substring
  • Tag ~? "regexp" for tag matches "regexp"
  • Tag /~? "regexp" for tag doesn't match "regexp"
  • qFile path for matching filepath path (relative to the music directory)
  • qBase dir for restrincting the search to subdirectory dir
  • qModSince time for restricting the search to files modified after some time
  • qNot query for negating a query

Notice that this doesn't implement the AudioFormat filters, because I'm not entirely sure how those work. At any rate like the rest of this stuff they can be implemented without breaking backwards compatibility because the user only creates Query's with the combinators anyway.

I haven't created tests for these yet, primarily because I haven't really been able to understand the test suite all that well. For example, why does this work? The default song doesn't have a title.

Edit: also, this closes #77, and is related to #123.

@iyefrat
Copy link
Contributor Author

iyefrat commented Jan 2, 2021

@psibi @joachifm @sol ?

@psibi
Copy link
Collaborator

psibi commented Jan 2, 2021

@iyefrat Sorry for the late reply. I don't have any oppositions in merging this. I'm slightly concerned that there are no tests for this. Is it possible to add minimal tests for the newly added functions ?

@iyefrat
Copy link
Contributor Author

iyefrat commented Jan 2, 2021

Yes if I wasn't clear, I want to add tests before this gets merged, it's just that I'm having trouble understanding how the song portion of the test suite works. For example this test seems to query for a song with title "Foo" on a database consisting of a song with no title, but it returns that song anyway. Can you explain to me what I'm missing here?

@psibi
Copy link
Collaborator

psibi commented Jan 2, 2021

@iyefrat To be honest, even I don't have much idea about it. Probably someone else can chime in and answer that.

But probably adding a new test module can be added for the new functions ?

@iyefrat
Copy link
Contributor Author

iyefrat commented Jan 2, 2021

@psibi It's just that the part of the test suite I'm asking about is the one about =? and all the functions are generalizations of that so I don't really think I can write the tests for the new functions until I understand that

@joachifm
Copy link
Contributor

joachifm commented Jan 2, 2021

Re: the test. It's been a long while, but at a glance it only exercises the parsing, it does not actually evaulate/simulate the query.

@psibi
Copy link
Collaborator

psibi commented Jan 2, 2021

@iyefrat Does the clarification from Joachifm help you ? Let me know if I should look further into it and I can likely get some time to do it tomorrow.

@iyefrat
Copy link
Contributor Author

iyefrat commented Jan 2, 2021

@psibi It kind of did. I went over the test code again and it does seem to just make sure that the command parses correctly, but now I'm just confused as to why it was designed this way, as the whole fake song part of this seems to be entirely redundant. Maybe to lay the groundwork for testing on an actual song library in the future?

Either way, I have implemented the tests. Because they only do parsing, they still rely on me having written the results correctly. I have checked that all the new queries actually work on my end, and this is the existing testing standard anyway.

src/Network/MPD/Commands/Query.hs Show resolved Hide resolved
changelog.md Show resolved Hide resolved
@psibi
Copy link
Collaborator

psibi commented Jan 2, 2021

Thank you!

@iyefrat iyefrat deleted the query branch January 15, 2021 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

search and find take a "base" keyword
3 participants