SearchIndexNameResolver.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Elasticsearch\SearchAdapter;
  7. use Magento\CatalogSearch\Model\Indexer\Fulltext;
  8. use Magento\Elasticsearch\Model\Config;
  9. /**
  10. * Alias name resolver
  11. * @api
  12. * @since 100.1.0
  13. */
  14. class SearchIndexNameResolver
  15. {
  16. /**
  17. * @var Config
  18. */
  19. private $clientConfig;
  20. /**
  21. * @param Config $clientConfig
  22. */
  23. public function __construct(
  24. Config $clientConfig
  25. ) {
  26. $this->clientConfig = $clientConfig;
  27. }
  28. /**
  29. * Returns the index (alias) name
  30. *
  31. * @param int $storeId
  32. * @param string $indexerId
  33. * @return string
  34. * @since 100.1.0
  35. */
  36. public function getIndexName($storeId, $indexerId)
  37. {
  38. $mappedIndexerId = $this->getIndexMapping($indexerId);
  39. return $this->clientConfig->getIndexPrefix() . '_' . $mappedIndexerId . '_' . $storeId;
  40. }
  41. /**
  42. * Get index name by indexer ID
  43. *
  44. * @param string $indexerId
  45. * @return string
  46. */
  47. private function getIndexMapping($indexerId)
  48. {
  49. if ($indexerId == Fulltext::INDEXER_ID) {
  50. $mappedIndexerId = 'product';
  51. } else {
  52. $mappedIndexerId = $indexerId;
  53. }
  54. return $mappedIndexerId;
  55. }
  56. }