Description
There are many classes and interfaces related to search results. Some of them seem to duplicate functionality or are in conflict with each other by exposing the same methods.
It seems as if even the core team is confused because sometimes one interface is implemented, but another's methods are also added, but partially only as method stubs.
Finally the similar names are extremely confusing and make it hard to reason about the code and see what it actually does.
These are the classes I'm talking about:
\Magento\Framework\Data\AbstractSearchCriteriaBuilder
\Magento\Framework\Data\AbstractSearchResult
\Magento\Framework\Data\SearchResultInterface
\Magento\Framework\Data\SearchResultIterator
\Magento\Framework\Data\SearchResultIteratorFactory
\Magento\Framework\Data\SearchResultProcessor
\Magento\Framework\Data\SearchResultProcessorFactory
\Magento\Framework\Data\SearchResultProcessorInterface
\Magento\Framework\Api\CriteriaInterface
\Magento\Framework\Api\SearchCriteria
\Magento\Framework\Api\SearchCriteriaBuilder
\Magento\Framework\Api\SearchResults
\Magento\Framework\Api\SearchResultsInterface
(This list excludes many classes in the same namespaces which don't help, but I would like to keep this issue focused on the SearchResults, which to me are the most confusing)
I'm not sure how to best resolve this issue, but I think the following changes would help.
- Rename
\Magento\Framework\Data\SearchResultInterface
to\Magento\Framework\Data\CollectionResultInterface
- Rename
\Magento\Framework\Data\SearchResultInterface::getSearchCriteria
to\Magento\Framework\Data\SearchResultInterface::getCriteria()
(or after the proposed rename:\Magento\Framework\Data\CollectionResultInterface::getCriteria()
, as it returns aCriteriaInterface
and not aSearchCriteriaInterface
instance. - Rename
\Magento\Framework\Data\SearchResultIterator
to\Magento\Framework\Data\CollectionResultIterator
- Rename
\Magento\Framework\Data\SearchResultIteratorFactory
to\Magento\Framework\Data\CollectionResultIteratorFactory
- Rename
\Magento\Framework\Data\SearchResultProcessor
to\Magento\Framework\Data\CollectionResultProcessor
- Rename
\Magento\Framework\Data\SearchResultProcessorFactory
to\Magento\Framework\Data\CollectionResultProcessorFactory
- Rename
\Magento\Framework\Data\SearchResultProcessorInterface
to\Magento\Framework\Data\CollectionResultProcessorInterface
- Rename
\Magento\Framework\Data\AbstractSearchResult
to\Magento\Framework\Data\AbstractCollectionResult
- Remove the method
\Magento\Framework\Data\AbstractSearchResult::setSearchCriteria()
, as this doesn't do anything, refers toApi\SearchCriteriaInterface
in the method signature and thus adds to confusion between the two parts of the framework. It seems as if someone was attempting to implement bothData\SearchResultInterface
andApi\SearchResultsInterface
.
These changes would help developers like myself understand how the code is intended to be used. The reason I didn't go ahead with a PR directly is because I might be totally on the wrong track. Please let me know if you agree or disagree with my suggestion. If I'm off track please tell me how these classes and interfaces are supposed to be used. If you prefer a different naming scheme, I'd be happy to implement that, too. It would be great if these two parts of the framework where more easily distinguishable.