diff --git a/app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php b/app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php index ad52f81bf8eda..06d037f24d958 100644 --- a/app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php +++ b/app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php @@ -68,6 +68,10 @@ public function apply() foreach ($items as $item) { $ids[] = (int)$item->getId(); } + + $this->collection->setPageSize(null); + $this->collection->setCurPage(null); + $this->collection->getSelect()->where('e.entity_id IN (?)', $ids); $orderList = join(',', $ids); $this->collection->getSelect()->reset(\Magento\Framework\DB\Select::ORDER); diff --git a/app/code/Magento/Elasticsearch/Test/Unit/Model/ResourceModel/Fulltext/Collection/SearchResultApplierTest.php b/app/code/Magento/Elasticsearch/Test/Unit/Model/ResourceModel/Fulltext/Collection/SearchResultApplierTest.php new file mode 100644 index 0000000000000..69bb4bf716bde --- /dev/null +++ b/app/code/Magento/Elasticsearch/Test/Unit/Model/ResourceModel/Fulltext/Collection/SearchResultApplierTest.php @@ -0,0 +1,113 @@ +collection = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->select = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->collection + ->method('getSelect') + ->willReturn($this->select); + + $this->searchResult = $this->getMockBuilder(SearchResultInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->document = $this->getMockBuilder(DocumentInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->document + ->method('getId') + ->willReturn(123); + + $this->searchResult + ->method('getItems') + ->willReturn([$this->document]); + + $this->size = 10; + $this->currentPage = 1; + + $this->object = new SearchResultApplier( + $this->collection, + $this->searchResult, + $this->size, + $this->currentPage + ); + } + + public function testApply(): void + { + $this->collection->expects($this->once()) + ->method('setPageSize') + ->with(null) + ->willReturn($this->collection); + + $this->collection->expects($this->once()) + ->method('setCurPage') + ->with(null) + ->willReturn($this->collection); + + $this->object->apply(); + } +}