/**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Magento\Customer\Model\Resource\Customer\Collection $collection */
     $collection = $this->customerFactory->create()->getCollection();
     // This is needed to make sure all the attributes are properly loaded
     foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
         $collection->addAttributeToSelect($metadata->getAttributeCode());
     }
     // Needed to enable filtering on name as a whole
     $collection->addNameToSelect();
     // Needed to enable filtering based on billing address attributes
     $collection->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left');
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $customers = [];
     /** @var \Magento\Customer\Model\Customer $customerModel */
     foreach ($collection as $customerModel) {
         $customers[] = $customerModel->getDataModel();
     }
     $searchResults->setItems($customers);
     return $searchResults;
 }