cancel
Showing results for 
Search instead for 
Did you mean: 

SearchCriteria too limited in AND/OR filtering

0 Kudos

SearchCriteria too limited in AND/OR filtering

Feature request from SamTay, posted on GitHub Apr 08, 2016

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.

6 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from pboisvert, posted on GitHub May 11, 2016

@choukalos can you take a look at this one Chuck?

apiuser
New Member

Comment from choukalos, posted on GitHub May 27, 2016

Hello @SamTay you are correct that's how search criteria works doc link.

What would you like to see for search criteria?

I've created an epic to track this request internally ( MAGETWO-53564 ).

apiuser
New Member

Comment from SamTay, posted on GitHub May 27, 2016

Ability to specify nested and/or logic, see above example.

apiuser
New Member

Comment from choukalos, posted on GitHub Jul 28, 2016

Thanks @SamTay for the insight. We're tracking internally.

For those on this thread, a change to search criteria would be a breaking change; how big of an impact would this be for you all?

apiuser
New Member

Comment from Ctucker9233, posted on GitHub Jul 29, 2016

@choukalos What do you mean by breaking change? If it breaks the search criteria so it doesn't work that would have a very negative impact. But maybe I don't fully understand the question you are asking.