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;
    }
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;
    }
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 ; }
Append default sort to all queries to get fully predictable search results.

Order by _score first and then by the id field.

@param array            $orders  Original orders.
@param MappingInterface $mapping Mapping.

@return array
Append default sort to all queries to get fully predictable search results .