Magento 2 · Service Contracts
Mastering SearchCriteria
AND/OR Filters, Pagination, Sorting
At first glance, SearchCriteria in Magento 2 looks generic and simple. In practice, though, many implementations fail because of FilterGroup logic, wrong assumptions about AND and OR, or repository queries that are more accidental than the result of deliberate query design.
18 min read
Repositories
Magento 2.4.8
Table of Contents
- 1. What SearchCriteria in Magento 2 actually is
- 2. Understanding AND and OR in SearchCriteria correctly
- 3. Using pagination and page sizes cleanly
- 4. Controlling sorting deliberately with SortOrder
- 5. SearchCriteria in repository practice
- 6. Common mistakes
- 7. SearchCriteria vs. direct Collection
- 8. Magento 2 support
- 9. Summary
- 10. FAQ
1. What SearchCriteria in Magento 2 actually is
SearchCriteria Magento 2 is the standardized language repositories use to describe list queries. Instead of thinking directly in terms of collections