Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Config Class Reference
Inheritance diagram for Config:
ClientOptionsInterface

Public Member Functions

 __construct (ScopeConfigInterface $scopeConfig, ClientResolver $clientResolver=null, EngineResolverInterface $engineResolver=null, $prefix=null)
 
 prepareClientOptions ($options=[])
 
 getElasticsearchConfigData ($field, $storeId=null)
 
 getSearchConfigData ($field, $storeId=null)
 
 isElasticsearchEnabled ()
 
 getIndexPrefix ()
 
 getEntityType ()
 

Data Fields

const ENGINE_NAME = 'elasticsearch'
 
const ELASTICSEARCH_TYPE_DOCUMENT = 'document'
 
const ELASTICSEARCH_TYPE_DEFAULT = 'product'
 
const ELASTICSEARCH_DEFAULT_TIMEOUT = 15
 

Protected Attributes

 $scopeConfig
 

Detailed Description

Elasticsearch config model @api

Since
100.1.0

Definition at line 21 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ScopeConfigInterface  $scopeConfig,
ClientResolver  $clientResolver = null,
EngineResolverInterface  $engineResolver = null,
  $prefix = null 
)

Constructor

Parameters
ScopeConfigInterface$scopeConfig
ClientResolver | null$clientResolver
EngineResolverInterface | null$engineResolver
string | null$prefix

Definition at line 74 of file Config.php.

79  {
80  $this->scopeConfig = $scopeConfig;
81  $this->clientResolver = $clientResolver ?: ObjectManager::getInstance()->get(ClientResolver::class);
82  $this->engineResolver = $engineResolver ?: ObjectManager::getInstance()->get(EngineResolverInterface::class);
83  $this->prefix = $prefix ?: $this->clientResolver->getCurrentEngine();
84  }

Member Function Documentation

◆ getElasticsearchConfigData()

getElasticsearchConfigData (   $field,
  $storeId = null 
)

Retrieve information from Elasticsearch search engine configuration

Parameters
string$field
int$storeId
Returns
string|int
Since
100.1.0

Definition at line 114 of file Config.php.

115  {
116  return $this->getSearchConfigData($this->prefix . '_' . $field, $storeId);
117  }
getSearchConfigData($field, $storeId=null)
Definition: Config.php:127

◆ getEntityType()

getEntityType ( )

Get Elasticsearch entity type

Returns
string
Since
100.1.0

Definition at line 161 of file Config.php.

162  {
164  }

◆ getIndexPrefix()

getIndexPrefix ( )

Get Elasticsearch index prefix

Returns
string
Since
100.1.0

Definition at line 150 of file Config.php.

151  {
152  return $this->getElasticsearchConfigData('index_prefix');
153  }
getElasticsearchConfigData($field, $storeId=null)
Definition: Config.php:114

◆ getSearchConfigData()

getSearchConfigData (   $field,
  $storeId = null 
)

Retrieve information from search engine configuration

Parameters
string$field
int | null$storeId
Returns
string|int
Since
100.1.0

Definition at line 127 of file Config.php.

128  {
129  $path = 'catalog/search/' . $field;
130  return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
131  }

◆ isElasticsearchEnabled()

isElasticsearchEnabled ( )

Return true if third party search engine is used

Returns
bool
Since
100.1.0

Definition at line 139 of file Config.php.

140  {
141  return in_array($this->engineResolver->getCurrentSearchEngine(), [self::ENGINE_NAME, self::ENGINE_NAME_5]);
142  }

◆ prepareClientOptions()

prepareClientOptions (   $options = [])

Return search client options

Parameters
array$options
Returns
array
Since
100.1.0

Since
100.1.0

Implements ClientOptionsInterface.

Definition at line 91 of file Config.php.

92  {
93  $defaultOptions = [
94  'hostname' => $this->getElasticsearchConfigData('server_hostname'),
95  'port' => $this->getElasticsearchConfigData('server_port'),
96  'index' => $this->getElasticsearchConfigData('index_prefix'),
97  'enableAuth' => $this->getElasticsearchConfigData('enable_auth'),
98  'username' => $this->getElasticsearchConfigData('username'),
99  'password' => $this->getElasticsearchConfigData('password'),
100  'timeout' => $this->getElasticsearchConfigData('server_timeout') ? : self::ELASTICSEARCH_DEFAULT_TIMEOUT,
101  ];
102  $options = array_merge($defaultOptions, $options);
103  return $options;
104  }
getElasticsearchConfigData($field, $storeId=null)
Definition: Config.php:114

Field Documentation

◆ $scopeConfig

$scopeConfig
protected

Definition at line 49 of file Config.php.

◆ ELASTICSEARCH_DEFAULT_TIMEOUT

const ELASTICSEARCH_DEFAULT_TIMEOUT = 15

Default Elasticsearch server timeout

Definition at line 43 of file Config.php.

◆ ELASTICSEARCH_TYPE_DEFAULT

const ELASTICSEARCH_TYPE_DEFAULT = 'product'

Elasticsearch default Entity type

Definition at line 38 of file Config.php.

◆ ELASTICSEARCH_TYPE_DOCUMENT

const ELASTICSEARCH_TYPE_DOCUMENT = 'document'

Elasticsearch Entity type

Definition at line 33 of file Config.php.

◆ ENGINE_NAME

const ENGINE_NAME = 'elasticsearch'

Search engine name

Definition at line 26 of file Config.php.


The documentation for this class was generated from the following file: