Search Criteria helps to build a custom request with different conditions.
Follow the below steps to use search criteria builder in Repository.
Step 1. Inject below dependency in your custom class
Magento\Framework\Api\SearchCriteriaBuilder
private $searchCriteriaBuilder;
.
public function __construct(
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
Step 2 : Use search criteria functions. here I am using addfilter
$this->searchCriteriaBuilder->addFilter('attribute_code', ['custom_attribute1', 'custom_attr2'] ,'in' );
Step 3 Create the Search criteria object
$searchCriteria = $this->searchCriteriaBuilder->create();
Step 4: Pass the search criteria object in getlist function the custom/code repository
$attributeList = $this->attributeRepository->getList($searchCriteria)->getItems();
Happy Coding 🙂