Smile\ElasticsuiteCore\Api\Index\MappingInterface::getIdField PHP Method

getIdField() public method

Field use as unique id for the doc.
public getIdField ( ) : Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface
return Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface
    public function getIdField();

Usage Example

 /**
  * 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
  */
 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;
 }