Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 69dcd37

Browse files
MAGETWO-75935: Search results is not the same for the same search queries
1 parent 96a06d5 commit 69dcd37

File tree

1 file changed

+10
-5
lines changed
  • app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext

1 file changed

+10
-5
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
6161
/**
6262
* @var string|null
6363
*/
64-
private $order = null;
64+
private $relevanceOrderDirection = null;
6565

6666
/**
6767
* @var string
@@ -361,13 +361,16 @@ protected function _renderFiltersBefore()
361361
[]
362362
);
363363

364-
if ($this->order && 'relevance' === $this->order['field']) {
365-
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
364+
if ($this->relevanceOrderDirection) {
365+
$this->getSelect()->order(
366+
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
367+
);
366368
}
367369

368370
/*
369371
* This order is required to force search results be the same
370372
* for the same requests and products with the same relevance
373+
* NOTE: this does not replace existing orders but ADDs one more
371374
*/
372375
$this->setOrder('entity_id');
373376

@@ -392,10 +395,12 @@ protected function _renderFilters()
392395
*/
393396
public function setOrder($attribute, $dir = Select::SQL_DESC)
394397
{
395-
$this->order = ['field' => $attribute, 'dir' => $dir];
396-
if ($attribute !== 'relevance') {
398+
if ($attribute === 'relevance') {
399+
$this->relevanceOrderDirection = $dir;
400+
} else {
397401
parent::setOrder($attribute, $dir);
398402
}
403+
399404
return $this;
400405
}
401406

0 commit comments

Comments
 (0)