4

Those two classes are very similar but I don't get the differences and why should one be used instead of another ?

  • Magento\Framework\Api\Search\SearchCriteriaBuilder => a handful of references in the Magento native code.
  • Magento\Framework\Api\SearchCriteriaBuilder => 200+ references

To me, there must be a good reason why the first one has been created but I don't get why.

Anyone can enlight me ?

1 Answer 1

6

They build different objects:

  • Magento\Framework\Api\SearchCriteria
  • Magento\Framework\Api\Search\SearchCriteria (which extends the former)

The Search/SearchCriteria has two additional methods:

/**
 * @return string
 */
public function getRequestName();

/**
 * @param string $requestName
 * @return $this
 */
public function setRequestName($requestName);

This request name is used by UI components to identify the search request. If I understand it correctly, the interfaces in Api/Search are meant for actual searches by the user, while the common Api/SearchResults and Api/SearchCriteria interfaces are used for any repositories (i.e. collection filtering and sorting)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.