V8-archive: Clean up multiple filter syntax

Created on 26 Dec 2018  ·  11Comments  ·  Source: directus/v8-archive

Multiple filters is now functional, but @WellingGuzman would like to clean up the syntax a bit so it's more intuitive.


From Welling:

The problem: it could be a bit ugly, just for the sake of the "array in url" thing:

filter[id][][between]=1,15&filter[id][][between]=30,45

Although to include ranges between 1 and 15, and 30 and 45. it should be an or.

Here where it gets ugly:

filter[id][0][between]=1,15&filter[id][0][logical]=or&filter[id][1][between]=30,45

This was implemented by https://github.com/directus/api/commit/b37f5bbb173849bf8383876185af48e26612f60b


I was thinking on trying to implement a parser to allow multiple fields without adding the array. In addiction to the default using array.

So it looks like this:

filter[id][between]=1,15&filter[id][between]=30,45

Instead of:

filter[id][][between]=1,15&filter[id][][between]=30,45
enhancement

Most helpful comment

I can tackle this next week...

May I suggest:
filter[<field>][<filter>][]=<value>&filter[<field>][<filter>][]=<value>&filter[<field>][logical]=<value>

This would render:

{
    "access_token": "<token>",
    "filter": {
        "<field>": {
            "<filter>": [
                "<value>",
                "<value>"
            ],
            "logical": "<logical>"
        }
    }
}

This way the program will sandwich the array under the field with the logical.
The issue with repeating the same field multiple times is that when the $_REQUEST object is parsed only one key can be used.

All 11 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I can tackle this next week...

May I suggest:
filter[<field>][<filter>][]=<value>&filter[<field>][<filter>][]=<value>&filter[<field>][logical]=<value>

This would render:

{
    "access_token": "<token>",
    "filter": {
        "<field>": {
            "<filter>": [
                "<value>",
                "<value>"
            ],
            "logical": "<logical>"
        }
    }
}

This way the program will sandwich the array under the field with the logical.
The issue with repeating the same field multiple times is that when the $_REQUEST object is parsed only one key can be used.

Related to: #576

Sorry, maybe my brain is fried... but can you post your suggested syntax as an example with dummy data?

@bjgajjar — what are your thoughts on this approach?

Posting the transformation - this is a real SQL query...
FILTERS:
filters[key][contains][]=[task]&filters[key][contains][]=[ticket]&filters[key][logical]=[or]
RAW SQL:
SELECT * FROM `joins_app_users_metadata` WHERE `key` LIKE '%task%' OR `key` LIKE '%ticket%';

To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.

This issue being closed does not mean it's not being considered.

I added this to in progress — that sound about right @philleepflorence ? :)

Yes, sounds about right - do we agree on the nomenclature?

Cool. Let's just get @rijkvanzanten and @bjgajjar to sign off on the naming... then we should be good!

Looks good to me 👍

Awesome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benhaynes picture benhaynes  ·  4Comments

ondronix picture ondronix  ·  3Comments

metalmarco picture metalmarco  ·  3Comments

andgar2010 picture andgar2010  ·  3Comments

Varulv1997 picture Varulv1997  ·  3Comments