Solved Filter albums using both AND and OR?
#1
*DOH* Wrong forum again *blush* sorry..please move at will.

Hi,

I need "this" to work to handle Albums, but I am having a hard time getting it to work.

I would like to get Albums that
1. span a certain time frame and
2. has similar genres; Eg. the genre string contains one or more of ["blues" "jazz", "swing"]

I made the filter below, expecting it to work, but it seems to ignore the "or" part IF the "and" part is present.
If I use just the "or" part, that part works as expected; returns only albums with certain genres.

I believe that the "and" part lists conditions that ALL have to be fulfilled, whereas the "or" part lists conditions where AT LEAST ONE have to be fulfilled.

Any help appreciated!

Is the query below supposed to work?

Code:
{
    "filter": {
        "and": [{
            "field": "year",
            "operator": "greaterthan",
            "value": "1969"
        }, {
            "field": "year",
            "operator": "lessthan",
            "value": "1980"
        }],
        "or": [{
            "field": "genre",
            "operator": "contains",
            "value": "jazz"
        }, {
            "field": "genre",
            "operator": "contains",
            "value": "blues"
        }, {
            "field": "genre",
            "operator": "contains",
            "value": "swing"
        }]
    }
}

(I used http://jsonlint.com to validate (and format for this forum) the json, and http://kodi.wiki/view/JSON-RPC_API/v6#Li...ter.Albums as a guide (along with threads on the subject).

The entire query I use is:
Code:
"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "filter": {"and": [{"field": "year","operator": "greaterthan","value": "1969"}, {"field": "year","operator": "lessthan","value": "1980"}],"or": [{"field": "genre","operator": "contains","value": "jazz"}, {"field": "genre","operator": "contains","value": "blues"}, {"field": "genre","operator": "contains","value": "swing"}]},  "properties": ["genre", "artist", "title", "year", "thumbnail"], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true }}, "id": "libAlbums"}

p.s. This problem could easily be down to my bool logic failing... but I hope not Smile
Reply
#2
Merry chrismas all.. and while you are here. Have a look at OP. ;-)
Reply
#3
Maybe you need another "and" like this:

and: [ and:[..., ...], or:[..., ..., ...] ]
Reply
#4
I think you are on to something. I probably need the and, or in a list. Will try that. Thanks!
Reply
#5
You were spot on friend! Smile Thanks!!

Final query that filters on both AND and OR, incase someone needs it:
Code:
{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "filter": {"and": [{"or": [{"field": "genre", "operator": "contains", "value": "jazz"}, {"field": "genre", "operator": "contains", "value": "blues"}, {"field": "genre", "operator": "contains", "value": "swing"}]}, {"and":[{"field": "year", "operator": "greaterthan", "value": "1959"}, {"field": "year", "operator": "lessthan", "value": "1970"}]}]},  "properties": ["albumlabel", "artist", "title", "year", "thumbnail"], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true }}, "id": "libAlbums"}
Reply

Logout Mark Read Team Forum Stats Members Help
Filter albums using both AND and OR?0