-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Suggestion] Api\SearchResultsInterface and Data\SearchResultInterface needs improvement #1419
Comments
Should I just go ahead with a PR for this as a base for discussion since the change will be impossible once M2 is released ;) |
Hopefully someone from Magento will respond, but regarding the proposed class names my personal opinion is that the name |
Thanks for your response, good point. However, there already is a class Another suggestion: Instead of using |
Maybe better to rename Class \Magento\Framework\Data\Collection to \Magento\Framework\Data\CollectionBuilder |
SearchCollection would be good too. |
@kandy The class @roshimon The class does not represent a collection of searches, so I don't think the name is fitting to be honest. |
Cool Vinai. |
@Vinai Why not? We configure query and on getIterator/getData methods call we obtains collection of documents in same way as builder create object |
@kandy Afaik builder is used for the creation of a single aggregate objects. A collection is used to manage access to multiple objects of the same type. Instantiation is not necessarily part of a collection (see |
Apologies, I should have looked at the code!
I agree. Builder pattern is about explicit object creation, which is not what
I think this is the main issue; as in Magento 1, the |
Please take what follows with a grain of salt, it's just what I think is the idea: |
Thanks, @Vinai, that's a really helpful explanation. Overall it sounds like quite a pragmatic but a clever approach, but it's brilliant that you're investing the time to make it better. If I'm able to find some time to get familiar with these classes then I might chime in again next week. Keep it up, guys! |
Hopefully @joshdifabio you got your answer if not please feel free to reopen the issue |
[EngCom] Public Pull Requests - MAGETWO-71539: Send different base currency in Google analytics #10508
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.
\Magento\Framework\Data\SearchResultInterface
to\Magento\Framework\Data\CollectionResultInterface
\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.\Magento\Framework\Data\SearchResultIterator
to\Magento\Framework\Data\CollectionResultIterator
\Magento\Framework\Data\SearchResultIteratorFactory
to\Magento\Framework\Data\CollectionResultIteratorFactory
\Magento\Framework\Data\SearchResultProcessor
to\Magento\Framework\Data\CollectionResultProcessor
\Magento\Framework\Data\SearchResultProcessorFactory
to\Magento\Framework\Data\CollectionResultProcessorFactory
\Magento\Framework\Data\SearchResultProcessorInterface
to\Magento\Framework\Data\CollectionResultProcessorInterface
\Magento\Framework\Data\AbstractSearchResult
to\Magento\Framework\Data\AbstractCollectionResult
\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.
The text was updated successfully, but these errors were encountered: