Smile\ElasticsuiteCore\Search\Request\SortOrder\SortOrderBuilder::addDefaultSortOrders PHP Method

addDefaultSortOrders() private method

Order by _score first and then by the id field.
private addDefaultSortOrders ( array $orders, Smile\ElasticsuiteCore\Api\Index\MappingInterface $mapping ) : array
$orders array Original orders.
$mapping Smile\ElasticsuiteCore\Api\Index\MappingInterface Mapping.
return array
    private function addDefaultSortOrders($orders, MappingInterface $mapping)
    {
        $defaultOrders = [SortOrderInterface::DEFAULT_SORT_FIELD => SortOrderInterface::SORT_DESC, $mapping->getIdField()->getName() => SortOrderInterface::SORT_DESC];
        if (count($orders) > 0) {
            $firstOrder = current($orders);
            if ($firstOrder['direction'] == SortOrderInterface::SORT_DESC) {
                $defaultOrders[SortOrderInterface::DEFAULT_SORT_FIELD] = SortOrderInterface::SORT_ASC;
                $defaultOrders[$mapping->getIdField()->getName()] = SortOrderInterface::SORT_ASC;
            }
        }
        foreach ($defaultOrders as $currentOrder => $direction) {
            if (!in_array($currentOrder, array_keys($orders))) {
                $orders[$currentOrder] = ['direction' => $direction];
            }
        }
        return $orders;
    }