-
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
Fixed Issue #17295 : Search REST API returns wrong total_count #20253
Conversation
Hi @ronak2ram. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@magento-engcom-team give me test instance |
Hi @ronak2ram. Thank you for your request. I'm working on Magento instance for you |
Hi @ronak2ram, here is your new Magento instance. |
Confirmed on the test instance. |
@ronak2ram currently your solution introduces a huge performance issue by sending a second search on each request to the search engine. I did not go into detail yet, but wouldn't it be possible, to resolve this issue by fixing the original call to the search engine so it calculates the correct total count? |
*/ | ||
public function getTotalCount(SearchCriteriaInterface $searchCriteria) | ||
{ | ||
$requestBuilder = \Magento\Framework\App\ObjectManager::getInstance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectManager must not be used directly here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidverholen I will remove ObjectManager in next commit.
} | ||
|
||
$request = $requestBuilder->create(); | ||
$searchResponse = $this->searchEngine->search($request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the search engine should not require a second search just to figure out the correct count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not find any other solution can you please suggest me a better solution to eliminate searchEngine?
@magento-engcom-team give me test instance |
Hi @ronak2ram. Thank you for your request. I'm working on Magento instance for you |
Hi @ronak2ram, here is your new Magento instance. |
Hello @davidverholen @orlangur |
Hi @ronak2ram , this solution seems to be more "On the point" since it mostly extends the mysql search adapter to reflect the correct total count (even if the page size is lower than the total count). However, you are introducing a new public method in the Query Response of the search framework which then probably needs to be implemented in all additional Search engines (like elasticsearch and 3rd party modules). I will try to investigate a bit deeper if I see a solution, without changing the public api of the search framework. If not, it seems to be a design problem of the search framework api, which seems to be missing exactly the method you introduced in your change. |
Hello @davidverholen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ronak2ram thanks for the pull request, please see my code review comments.
@buskamuza @melnikovi please review this contribution, in order to process it we'll need an approval of adding \Magento\Framework\Search\Response\QueryResponse::getTotalCount public method.
* | ||
* @var array | ||
*/ | ||
protected $countSqlSkipParts = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the access modifier to private
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTotalCount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@buskamuza @melnikovi can you please take a look if we can allow adding this method to the framework. It appears there is no other way to return the total count of the search result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class has count method already, that seem to have similar purpose. Are there cases when count that it uses is not efficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@melnikovi Count method returns a total count of the search result items of the current page.
We make getTotalCount for the return all pages items count.
* | ||
* @return Select | ||
*/ | ||
protected function getSelectCountSql($query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change method access modifier to private
* | ||
* @return int | ||
*/ | ||
public function getSize($query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change method access modifier to private
* | ||
* @var int | ||
*/ | ||
protected $totalCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change property access modifier to private
/** | ||
* @param Document[] $documents | ||
* @param AggregationInterface $aggregations | ||
* @param Total size int $size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the phpdoc: @param int $size Total size
Hello Masters @sivaschenko @melnikovi @davidverholen Please Review PR : #21713 |
Thanks @ronak2ram ! As all the concerns in the review were fixed, I approved the new pull request, closing this one as outdated. |
Hi @ronak2ram, thank you for your contribution! |
Description (*)
I added function for getting total_count of result item.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Request :
rest/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filterGroups][0][filters][0][field]=search_term&searchCriteria[filterGroups][0][filters][0][conditionType]=like&searchCriteria[filterGroups][0][filters][0][value]=test&searchCriteria[current_page]=1&searchCriteria[page_size]=2
Response :
Contribution checklist (*)