Skip to content

SearchCriteria too limited in AND/OR filtering #4060

@samtay

Description

@samtay

From what I understand, filters are combined with an OR logic within a particular filter group, and filter groups are combined with AND logic within search criteria. This is unfortunately not listed in documentation, but is what users on stackoverflow have discovered.

This is very limiting. For example, it is impossible to filter the product repository by two date intervals: suppose I want to grab all the products that are either new or on sale. This would involve logic like so:

(filter['special_price_from', 'to', $now] && filter['special_price_to', 'from', $now])
|| (filter['news_from_date', 'to', $now] && filter['news_to_date', 'from', $now])

But this is impossible to build as searchCriteria. The outer OR would dictate that everything needs to be in one filter group, but within each interval we also need AND combinations, which are impossible within one filter group. Because of these limitations, I have been forced to use collections directly instead of using the repository abstraction layer. Please let me know if there is a more flexible way to have and/or combinations.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions