ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter;
|
||||
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @param array $documentData
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return array
|
||||
*/
|
||||
public function prepareDocuments(array $documentData, int $storeId, string $indexerId): array;
|
||||
|
||||
/**
|
||||
* @param array $documents
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveDocuments(array $documents, int $storeId, string $indexerId): void;
|
||||
|
||||
/**
|
||||
* @param array $documentIds
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteDocuments(array $documentIds, int $storeId, string $indexerId): void;
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return void
|
||||
*/
|
||||
public function cleanIndex(int $storeId, string $indexerId): void;
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return void
|
||||
*/
|
||||
public function checkIndex(int $storeId, string $indexerId): void;
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @param string $indexerId
|
||||
* @return void
|
||||
*/
|
||||
public function updateAlias(int $storeId, string $indexerId): void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function ping(): bool;
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Elasticsearch7;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\Indexer\Data\DataMapperResolverInterface;
|
||||
use Amasty\ElasticSearch\Api\Data\Indexer\Structure\IndexBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Adapter\AdapterInterface;
|
||||
use Amasty\ElasticSearch\Model\Adapter\FieldMappingBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Adapter\Index\IndexNameResolver;
|
||||
use Amasty\ElasticSearch\Model\Adapter\SaveQueryBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Client\ClientInterface;
|
||||
use Amasty\ElasticSearch\Model\Client\ClientRepositoryInterface;
|
||||
use Amasty\ElasticSearch\Model\Debug;
|
||||
use Amasty\ElasticSearch\Model\Indexer\Structure\EntityBuilder as EntityStructureBuilder;
|
||||
use Exception;
|
||||
|
||||
class Elasticsearch implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var FieldMappingBuilderInterface
|
||||
*/
|
||||
private $fieldMappingBuilder;
|
||||
|
||||
/**
|
||||
* @var IndexNameResolver
|
||||
*/
|
||||
private $indexNameResolver;
|
||||
|
||||
/**
|
||||
* @var ClientRepositoryInterface
|
||||
*/
|
||||
private $clientRepository;
|
||||
|
||||
/**
|
||||
* @var IndexBuilderInterface
|
||||
*/
|
||||
private $indexBuilder;
|
||||
|
||||
/**
|
||||
* @var EntityStructureBuilder
|
||||
*/
|
||||
private $entityStructureBuilder;
|
||||
|
||||
/**
|
||||
* @var DataMapperResolverInterface
|
||||
*/
|
||||
private $dataMapperResolver;
|
||||
|
||||
/**
|
||||
* @var SaveQueryBuilderInterface
|
||||
*/
|
||||
private $saveQueryBuilder;
|
||||
|
||||
/**
|
||||
* @var Debug
|
||||
*/
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* @var ClientInterface|null
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var string[] ['store_id' => 'index_name']
|
||||
*/
|
||||
private $indexNameByStore = [];
|
||||
|
||||
public function __construct(
|
||||
IndexNameResolver $indexNameResolver,
|
||||
ClientRepositoryInterface $clientRepository,
|
||||
IndexBuilderInterface $indexBuilder,
|
||||
EntityStructureBuilder $entityStructureBuilder,
|
||||
FieldMappingBuilderInterface $fieldMappingBuilder,
|
||||
DataMapperResolverInterface $dataMapperResolver,
|
||||
SaveQueryBuilderInterface $saveQueryBuilder,
|
||||
Debug $debug,
|
||||
?ClientInterface $client = null
|
||||
) {
|
||||
$this->indexNameResolver = $indexNameResolver;
|
||||
$this->clientRepository = $clientRepository;
|
||||
$this->indexBuilder = $indexBuilder;
|
||||
$this->entityStructureBuilder = $entityStructureBuilder;
|
||||
$this->fieldMappingBuilder = $fieldMappingBuilder;
|
||||
$this->dataMapperResolver = $dataMapperResolver;
|
||||
$this->saveQueryBuilder = $saveQueryBuilder;
|
||||
$this->debug = $debug;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function prepareDocuments(array $documentData, int $storeId, string $indexerId): array
|
||||
{
|
||||
$documents = [];
|
||||
if (!empty($documentData)) {
|
||||
$documents = $this->dataMapperResolver->mapEntityData(
|
||||
$documentData,
|
||||
$storeId,
|
||||
['indexer_id' => $indexerId]
|
||||
);
|
||||
}
|
||||
|
||||
return $documents;
|
||||
}
|
||||
|
||||
public function saveDocuments(array $documents, int $storeId, string $indexerId): void
|
||||
{
|
||||
if (!empty($documents)) {
|
||||
try {
|
||||
$indexName = $this->indexNameResolver->getIndexName($indexerId, $storeId, $this->indexNameByStore);
|
||||
if ($this->getClient()->indexExists($indexName)) {
|
||||
$query = $this->saveQueryBuilder->execute($documents, $indexName);
|
||||
$this->getClient()->bulkQuery($query);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->debug->debug($e);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteDocuments(array $documentIds, int $storeId, string $indexerId): void
|
||||
{
|
||||
try {
|
||||
$indexName = $this->indexNameResolver->getIndexName($indexerId, $storeId, $this->indexNameByStore);
|
||||
if (!$this->getClient()->indexExists($indexName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = $this->saveQueryBuilder->execute(
|
||||
$documentIds,
|
||||
$indexName,
|
||||
SaveQueryBuilderInterface::BULK_ACTION_DELETE
|
||||
);
|
||||
$this->getClient()->bulkQuery($query);
|
||||
} catch (Exception $e) {
|
||||
$this->debug->debug($e);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanIndex(int $storeId, string $indexerId): void
|
||||
{
|
||||
// needed to fix bug with double indices in alias because of second reindex in same process
|
||||
unset($this->indexNameByStore[$storeId]);
|
||||
|
||||
$this->checkIndex($storeId, $indexerId);
|
||||
$indexName = $this->indexNameResolver->getIndexName($indexerId, $storeId, $this->indexNameByStore);
|
||||
if ($this->getClient()->isEmptyIndex($indexName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$indexPattern = $this->indexNameResolver->getIndexAlias($indexerId, $storeId) . '_v';
|
||||
$version = (int)(str_replace($indexPattern, '', $indexName));
|
||||
$newIndexName = $indexPattern . (++$version);
|
||||
|
||||
if ($this->getClient()->indexExists($newIndexName)) {
|
||||
$this->getClient()->deleteIndex($newIndexName);
|
||||
}
|
||||
$this->prepareIndex($storeId, $newIndexName, $indexerId);
|
||||
}
|
||||
|
||||
public function checkIndex(int $storeId, string $indexerId): void
|
||||
{
|
||||
$indexName = $this->indexNameResolver->getIndexName($indexerId, $storeId, $this->indexNameByStore);
|
||||
if (!$this->getClient()->indexExists($indexName)) {
|
||||
$this->prepareIndex($storeId, $indexName, $indexerId);
|
||||
}
|
||||
|
||||
$alias = $this->indexNameResolver->getIndexAlias($indexerId, $storeId);
|
||||
if (!$this->getClient()->existsAlias($alias, $indexName)) {
|
||||
$this->getClient()->updateAlias($alias, $indexName);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAlias(int $storeId, string $indexerId): void
|
||||
{
|
||||
if (!isset($this->indexNameByStore[$storeId])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$alias = $this->indexNameResolver->getIndexAlias($indexerId, $storeId);
|
||||
$oldIndex = $this->indexNameResolver->getIndexNameByAlias($alias, $storeId, $this->indexNameByStore);
|
||||
|
||||
if (!empty($oldIndex)) {
|
||||
$params['body']['actions'][] = ['remove' => ['alias' => $alias, 'index' => $oldIndex]];
|
||||
}
|
||||
$params['body']['actions'][] = ['add' => ['alias' => $alias, 'index' => $this->indexNameByStore[$storeId]]];
|
||||
|
||||
$this->getClient()->updateAliases($params);
|
||||
|
||||
if ($oldIndex) {
|
||||
$this->getClient()->deleteIndex($oldIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public function ping(): bool
|
||||
{
|
||||
return $this->getClient()->ping();
|
||||
}
|
||||
|
||||
private function prepareIndex(int $storeId, string $indexName, string $indexerId): void
|
||||
{
|
||||
$this->indexBuilder->setStoreId($storeId);
|
||||
$this->getClient()->createIndex($indexName, $this->indexBuilder->build());
|
||||
$mappingData = $this->fieldMappingBuilder->execute(
|
||||
$indexName,
|
||||
$storeId,
|
||||
$this->entityStructureBuilder->build($indexerId)
|
||||
);
|
||||
$this->getClient()->putMapping($mappingData);
|
||||
|
||||
$this->indexNameByStore[$storeId] = $indexName;
|
||||
}
|
||||
|
||||
private function getClient(): ClientInterface
|
||||
{
|
||||
if ($this->client === null) {
|
||||
$this->client = $this->clientRepository->get();
|
||||
}
|
||||
return $this->client;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Elasticsearch7;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Adapter\FieldMappingBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Config;
|
||||
use Amasty\ElasticSearch\Model\Indexer\Structure\DynamicTemplateMapper;
|
||||
use Amasty\ElasticSearch\Model\Indexer\Structure\EntityBuilder\Product;
|
||||
|
||||
class FieldMappingBuilder implements FieldMappingBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var DynamicTemplateMapper
|
||||
*/
|
||||
private $dynamicTemplateMapper;
|
||||
|
||||
public function __construct(Config $config, DynamicTemplateMapper $dynamicTemplateMapper)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->dynamicTemplateMapper = $dynamicTemplateMapper;
|
||||
}
|
||||
|
||||
public function execute(string $index, int $storeId, array $fields): array
|
||||
{
|
||||
$entityType = $this->config->getEntityType();
|
||||
|
||||
$params = [
|
||||
'index' => $index,
|
||||
'type' => $entityType,
|
||||
'body' => [
|
||||
$entityType => [
|
||||
'properties' => [],
|
||||
'dynamic_templates' => [
|
||||
$this->dynamicTemplateMapper->map($storeId)
|
||||
],
|
||||
'numeric_detection' => false,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$isAllowSpecialChars = $this->config->allowSpecialChars($storeId);
|
||||
$hasStemming = $this->config->hasStemming($storeId);
|
||||
foreach ($fields as $field => $fieldInfo) {
|
||||
if ($fieldInfo['type'] === Product::ATTRIBUTE_TYPE_TEXT) {
|
||||
$fieldInfo['fielddata'] = true;
|
||||
|
||||
if ($isAllowSpecialChars) {
|
||||
$fieldInfo['analyzer'] = 'allow_spec_chars';
|
||||
}
|
||||
|
||||
if ($hasStemming) {
|
||||
$fieldInfo['fields']['stemming'] = [
|
||||
'type' => Product::ATTRIBUTE_TYPE_TEXT,
|
||||
'fielddata' => true,
|
||||
'analyzer' => 'stem',
|
||||
'index' => true
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$params['body'][$entityType]['properties'][$field] = $fieldInfo;
|
||||
}
|
||||
$params['include_type_name'] = true;
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Elasticsearch7;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Adapter\SaveQueryBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Config;
|
||||
|
||||
class SaveQueryBuilder implements SaveQueryBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function execute(array $documents, string $indexName, string $action = self::BULK_ACTION_INDEX): array
|
||||
{
|
||||
$entityType = $this->config->getEntityType();
|
||||
|
||||
$bulkArray = [
|
||||
'index' => $indexName,
|
||||
'type' => $entityType,
|
||||
'body' => [],
|
||||
'refresh' => true,
|
||||
];
|
||||
|
||||
foreach ($documents as $id => $document) {
|
||||
$bulkArray['body'][] = [
|
||||
$action => [
|
||||
'_id' => $id,
|
||||
'_type' => $entityType,
|
||||
'_index' => $indexName
|
||||
]
|
||||
];
|
||||
if ($action === self::BULK_ACTION_INDEX) {
|
||||
$bulkArray['body'][] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
return $bulkArray;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Elasticsearch8;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Adapter\FieldMappingBuilderInterface;
|
||||
use Amasty\ElasticSearch\Model\Config;
|
||||
use Amasty\ElasticSearch\Model\Indexer\Structure\DynamicTemplateMapper;
|
||||
use Amasty\ElasticSearch\Model\Indexer\Structure\EntityBuilder\Product;
|
||||
|
||||
class FieldMappingBuilder implements FieldMappingBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var DynamicTemplateMapper
|
||||
*/
|
||||
private $dynamicTemplateMapper;
|
||||
|
||||
public function __construct(Config $config, DynamicTemplateMapper $dynamicTemplateMapper)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->dynamicTemplateMapper = $dynamicTemplateMapper;
|
||||
}
|
||||
|
||||
public function execute(string $index, int $storeId, array $fields): array
|
||||
{
|
||||
$params = [
|
||||
'index' => $index,
|
||||
'body' => [
|
||||
'properties' => [],
|
||||
'dynamic_templates' => [
|
||||
$this->dynamicTemplateMapper->map($storeId)
|
||||
],
|
||||
'numeric_detection' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$isAllowSpecialChars = $this->config->allowSpecialChars($storeId);
|
||||
$hasStemming = $this->config->hasStemming($storeId);
|
||||
foreach ($fields as $field => $fieldInfo) {
|
||||
if ($fieldInfo['type'] === Product::ATTRIBUTE_TYPE_TEXT) {
|
||||
$fieldInfo['fielddata'] = true;
|
||||
|
||||
if ($isAllowSpecialChars) {
|
||||
$fieldInfo['analyzer'] = 'allow_spec_chars';
|
||||
}
|
||||
|
||||
if ($hasStemming) {
|
||||
$fieldInfo['fields']['stemming'] = [
|
||||
'type' => Product::ATTRIBUTE_TYPE_TEXT,
|
||||
'fielddata' => true,
|
||||
'analyzer' => 'stem',
|
||||
'index' => true
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$params['body']['properties'][$field] = $fieldInfo;
|
||||
}
|
||||
$params['include_type_name'] = true;
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Elasticsearch8;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Adapter\SaveQueryBuilderInterface;
|
||||
|
||||
class SaveQueryBuilder implements SaveQueryBuilderInterface
|
||||
{
|
||||
public function execute(array $documents, string $indexName, string $action = self::BULK_ACTION_INDEX): array
|
||||
{
|
||||
$bulkArray = [
|
||||
'index' => $indexName,
|
||||
'body' => [],
|
||||
'refresh' => true,
|
||||
];
|
||||
|
||||
foreach ($documents as $id => $document) {
|
||||
$bulkArray['body'][] = [
|
||||
$action => [
|
||||
'_id' => $id,
|
||||
'_index' => $indexName
|
||||
]
|
||||
];
|
||||
if ($action === self::BULK_ACTION_INDEX) {
|
||||
$bulkArray['body'][] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
return $bulkArray;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter;
|
||||
|
||||
interface FieldMappingBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $index
|
||||
* @param array $fields
|
||||
* @param int $storeId
|
||||
* @return array
|
||||
*/
|
||||
public function execute(string $index, int $storeId, array $fields): array;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Index;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Client\ClientInterface;
|
||||
use Amasty\ElasticSearch\Model\Client\ClientRepositoryInterface;
|
||||
use Amasty\ElasticSearch\Model\Config;
|
||||
|
||||
class IndexNameResolver
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var ClientRepositoryInterface
|
||||
*/
|
||||
private $clientRepository;
|
||||
|
||||
/**
|
||||
* @var ClientInterface|null
|
||||
*/
|
||||
private $client;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
ClientRepositoryInterface $clientRepository,
|
||||
?ClientInterface $client = null
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->clientRepository = $clientRepository;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function getIndexAlias(string $indexerId, int $storeId): string
|
||||
{
|
||||
return $this->config->getIndexName($indexerId, $storeId);
|
||||
}
|
||||
|
||||
public function getIndexName(string $indexerId, int $storeId, array $preparedIndexName = []): string
|
||||
{
|
||||
// TODO: check original method for Xsearch
|
||||
if (!isset($preparedIndexName[$storeId])) {
|
||||
$alias = $this->getIndexAlias($indexerId, $storeId);
|
||||
$indexName = $this->getIndexNameByAlias($alias, $storeId);
|
||||
|
||||
if (empty($indexName)) {
|
||||
$indexName = $alias . '_v1';
|
||||
}
|
||||
|
||||
return $indexName;
|
||||
}
|
||||
|
||||
return $preparedIndexName[$storeId];
|
||||
}
|
||||
|
||||
public function getIndexNameByAlias(string $alias, int $storeId, array $preparedIndexName = []): string
|
||||
{
|
||||
$storeIndex = '';
|
||||
if ($this->getClient()->existsAlias($alias)) {
|
||||
$indexPattern = $alias . '_v';
|
||||
|
||||
$alias = $this->getClient()->getAlias($alias);
|
||||
$indices = array_keys($alias);
|
||||
natsort($indices);
|
||||
|
||||
foreach ($indices as $index) {
|
||||
if (strpos($index, $indexPattern) === 0) {
|
||||
if (isset($preparedIndexName[$storeId]) && $preparedIndexName[$storeId] == $index) {
|
||||
continue;
|
||||
}
|
||||
$storeIndex = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $storeIndex;
|
||||
}
|
||||
|
||||
private function getClient(): ?ClientInterface
|
||||
{
|
||||
if ($this->client === null) {
|
||||
$this->client = $this->clientRepository->get();
|
||||
}
|
||||
return $this->client;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter\Opensearch;
|
||||
|
||||
use Amasty\ElasticSearch\Model\Adapter\Elasticsearch8\FieldMappingBuilder as Elasticsearch8FieldMappingBuilder;
|
||||
use Amasty\ElasticSearch\Model\Adapter\FieldMappingBuilderInterface;
|
||||
|
||||
class FieldMappingBuilder implements FieldMappingBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Elasticsearch8FieldMappingBuilder
|
||||
*/
|
||||
private $fieldMappingBuilder;
|
||||
|
||||
public function __construct(Elasticsearch8FieldMappingBuilder $fieldMappingBuilder)
|
||||
{
|
||||
$this->fieldMappingBuilder = $fieldMappingBuilder;
|
||||
}
|
||||
|
||||
public function execute(string $index, int $storeId, array $fields): array
|
||||
{
|
||||
$result = $this->fieldMappingBuilder->execute($index, $storeId, $fields);
|
||||
unset($result['include_type_name']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\Adapter;
|
||||
|
||||
interface SaveQueryBuilderInterface
|
||||
{
|
||||
public const BULK_ACTION_INDEX = 'index';
|
||||
public const BULK_ACTION_DELETE = 'delete';
|
||||
|
||||
/**
|
||||
* @param array $documents
|
||||
* @param string $indexName
|
||||
* @param string $action
|
||||
* @return array
|
||||
*/
|
||||
public function execute(array $documents, string $indexName, string $action = self::BULK_ACTION_INDEX): array;
|
||||
}
|
||||
Reference in New Issue
Block a user