Filter queries seem to stop working when combining multiple?

Hi, were are trying to use filter queries on a list page for a content type to allow users to filter down the items shown.

The content type has various multi-options fields in its model, each selecting from items in a different data source (e.g. pick zero or more ‘states’, ‘audiences’ etc).

We want the user to be able to filter by selecting from a set of drop downs (which load their options from these same data sources), so e.g show me items (tagged state1 OR state2) AND (‘tagged audienceA OR audienceB’)

When doing simple filters, either by states alone, or one state & one audience, this seems to work fine. When you select more than one from a type though, the filters appear to ‘break’ and the wrong results are returned.

I’m not sure if this is supposed to work and we are just using the API wrong, or a bug? Seems a pretty standard use case though.

Any help appreciated, thanks!


Examples:

No filters, all items - works fine:
https://api.storyblok.com/v2/cdn/stories/?version=published&cv=1630917433&starts_with=service-providers%2F&is_startpage=false&sort_by=name%3Aasc&per_page=15&page=1&token=vlj2rvPX6fPHPGF7vVVflAtt

Filter by multiple states - works fine:
https://api.storyblok.com/v2/cdn/stories?cv=1630979253&filter_query[states][in_array]=nsw%2Cnt&is_startpage=false&page=1&per_page=15&sort_by=name%3Aasc&starts_with=service-providers%2F&token=vlj2rvPX6fPHPGF7vVVflAtt&version=published

Filter by multiple service types - works fine:
https://api.storyblok.com/v2/cdn/stories?cv=1630979253&filter_query[service_type][in_array]=disability-support&is_startpage=false&page=1&per_page=15&sort_by=name%3Aasc&starts_with=service-providers%2F&token=vlj2rvPX6fPHPGF7vVVflAtt&version=published

Filter by multipe states and 1 service type - states working, service type ignored:
https://api.storyblok.com/v2/cdn/stories?cv=1630979253&filter_query[service_type][in_array]=disability-support&filter_query[states][in_array]=nsw%2Cnt&is_startpage=false&page=1&per_page=15&sort_by=name%3Aasc&starts_with=service-providers%2F&token=vlj2rvPX6fPHPGF7vVVflAtt&version=published

Filter by multiple states AND multiple service types - service types working, states ignored:
https://api.storyblok.com/v2/cdn/stories?cv=1630979253&filter_query[service_type][in_array]=financial-matters%2Cknowing-my-rights&filter_query[states][in_array]=nsw%2Cnt&is_startpage=false&page=1&per_page=15&sort_by=name%3Aasc&starts_with=service-providers%2F&token=vlj2rvPX6fPHPGF7vVVflAtt&version=published

Hello @adam_grade !

We’ll take a look at your find and come back to you after analyzing the case.

Best regards
Hannes

Thanks @Hannes.

If it helps, we’ve had to launch the site with it like this already, so the issue can be seen in browser also at pages such as www.compass.info/resources/ … may give some context to what we are trying to do.

Thanks,
Adam

Been a few weeks, we’re still having this issue… any update or info @Hannes

Thanks,
Adan

Hello @adam_grade ,

unfortunately, I don’t have an update yet but I will inform you instantly when I’ve news for you.

Best regards
Hannes

Hello @adam_grade,

my colleagues added a new operator any_in_array which solves this issue. Now the queries will work as expected.

Best regards
Hannes

Wow, thanks very much @Hannes , we’ll try that out here and let you know.

Adam

1 Like

Just to let you know @Hannes (and anyone else needing this feature), we changed all uses of in_array to any_in_array in our search filters, and it now works exactly as expected. Thanks very much for the fix.

1 Like

Hey, I just spend multiple hours on the same problem.

This should be in the docs!

Hello @matovincetic,

we have some information about the two *_in_array variants here Storyblok API Documentation and here Storyblok API Documentation

Can you give us a hint of what information is missing, please?

Best regards
Hannes

Hey Hannes, sorry! This is my mistake. I accused you wrongly.

I have never seen the docs for content delivery API v2 because I always googled »Storyblok API« and Google always refered me to V1.

I take it all back.

Thanks for providing me with the Link!

P. s.: This proives once again: a developer is only as good as his googling skills…

1 Like

Hello @matovincetic,

no problem! Thanks for the feedback :slight_smile:

Best regards
Hannes