Skip to content

Commit

Permalink
Sort results by size (only working with integer values)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerCalli committed Aug 19, 2020
1 parent 8756204 commit 76f4a96
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use Elastica\Query;
use Elastica\Query\BoolQuery;
use FondOfSpryker\Shared\ProductPageSearchExpander\ProductPageSearchExpanderConstants;
use Generated\Shared\Search\PageIndexMap;
use InvalidArgumentException;
use Spryker\Client\Kernel\AbstractPlugin;
use Spryker\Client\SearchElasticsearch\Config\SortConfig;
use Spryker\Client\SearchExtension\Dependency\Plugin\QueryExpanderPluginInterface;
use Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface;

Expand Down Expand Up @@ -43,10 +45,26 @@ public function expandQuery(QueryInterface $searchQuery, array $requestParameter
);

$boolQuery->addMust($matchQuery);
$this->addSort($searchQuery->getSearchQuery());

return $searchQuery;
}

/**
* @param \Elastica\Query $searchQuery
*
* @return void
*/
protected function addSort(Query $searchQuery): void
{
$searchQuery->addSort([
PageIndexMap::INTEGER_SORT . '.' . ProductPageSearchExpanderConstants::SIZE => [
'order' => SortConfig::DIRECTION_ASC,
'mode' => 'min',
],
]);
}

/**
* @param \Elastica\Query $query
*
Expand Down

0 comments on commit 76f4a96

Please sign in to comment.