segler-alex / radiobrowser-api-rust

radio-browser API implementation in rust
GNU Affero General Public License v3.0
231 stars 99 forks source link

Change tagList filter semantics #9

Closed alivannikov closed 1 year ago

alivannikov commented 4 years ago

Currently tags in tagList parameter have AND semantics, meaning that all values should match. However OR semantics may be more useful in practice. For example I am interested in Death Metal music and 60s music. This is rare combination to be present in one particular station and most probably such request will lead to empty result set. However, what user really wants to be returned is Death Metal stations + 60s stations.

segler-alex commented 4 years ago

the AND semantics is the one that you can NOT emulate. the OR semantics can be emultated with just doing 2 requests, one for the first tag and one for the second and combining the result. i will not change the default behaviour to OR semantics because of that. but i also think, that there should be a way to ask the API for TAG1 OR TAG2, this will be an additional feature in the endpoint i have to think about. it should be not to complicated. thanks for your input!

alivannikov commented 4 years ago

You can easily emulate AND semantics by following the same logic. Just doing 2 requests, but taking intersection of results, not union. But yes, OR semantics can be separate endpoint/operation of course. Thank you for considering implementation of this feature!

alivannikov commented 4 years ago

@segler-alex Does this require something else except concatenating LIKE clauses from tagList with OR instead of AND here: https://github.com/segler-alex/radiobrowser-api-rust/blob/master/src/db/db_mysql/mod.rs#L546 And adding new endpoint parameter (if we want to keep old one)?

segler-alex commented 4 years ago

it would work, if the user does only send tags and nothing else. you could add "(" and ")" arround the whole task list so the rest will not get destroyed by it.

do you think only tags should have or semantics or do you think all search attributes should be combined with or?

alivannikov commented 4 years ago

No no, different search attributes should be combined with AND of course. I think this is how filtering usually works on search related web sites. Filters are combined with AND, filter values inside particular filter with OR. For example on clothes shop it may be size and color filters. You select 'black', 'blue', 'M', 'L'. So, naturally speaking you are looking for black or blue jacket which is size M or L. It does not make sense to query for size M AND L, it will always lead to empty result. From other side you do not want to see all M jackets, but only black or blue ones. It will not work if you combine size and color with OR.

alivannikov commented 4 years ago

@segler-alex Would you mind to do this small change? I have some troubles to set up local env to verify that it actually works.