Skip to content

Commit

Permalink
Merge pull request #3877 from magento-engcom/1-es6-2.3-develop
Browse files Browse the repository at this point in the history
[EngCom] Elasticsearch 6 Support
  • Loading branch information
joanhe authored Mar 15, 2019
2 parents c7c7e3d + a814747 commit f3d7a0d
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 105 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ cache:
- $HOME/node_modules
- $HOME/yarn.lock
before_install:
- curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.0/elasticsearch-2.3.0.deb && sudo dpkg -i --force-confnew elasticsearch-2.3.0.deb && sudo service elasticsearch restart
- ./dev/travis/before_install.sh
install: composer install --no-interaction
before_script: ./dev/travis/before_script.sh
Expand Down
16 changes: 11 additions & 5 deletions app/code/Magento/Elasticsearch/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Config implements ClientOptionsInterface
*/
const ENGINE_NAME = 'elasticsearch';

private const ENGINE_NAME_5 = 'elasticsearch5';

/**
* Elasticsearch Entity type
*/
Expand Down Expand Up @@ -64,23 +62,31 @@ class Config implements ClientOptionsInterface
private $engineResolver;

/**
* Constructor
* Available Elasticsearch engines.
*
* @var array
*/
private $engineList;

/**
* @param ScopeConfigInterface $scopeConfig
* @param ClientResolver|null $clientResolver
* @param EngineResolverInterface|null $engineResolver
* @param string|null $prefix
* @param array $engineList
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
ClientResolver $clientResolver = null,
EngineResolverInterface $engineResolver = null,
$prefix = null
$prefix = null,
$engineList = []
) {
$this->scopeConfig = $scopeConfig;
$this->clientResolver = $clientResolver ?: ObjectManager::getInstance()->get(ClientResolver::class);
$this->engineResolver = $engineResolver ?: ObjectManager::getInstance()->get(EngineResolverInterface::class);
$this->prefix = $prefix ?: $this->clientResolver->getCurrentEngine();
$this->engineList = $engineList;
}

/**
Expand Down Expand Up @@ -138,7 +144,7 @@ public function getSearchConfigData($field, $storeId = null)
*/
public function isElasticsearchEnabled()
{
return in_array($this->engineResolver->getCurrentSearchEngine(), [self::ENGINE_NAME, self::ENGINE_NAME_5]);
return in_array($this->engineResolver->getCurrentSearchEngine(), $this->engineList);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions app/code/Magento/Elasticsearch/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\Converter" />
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Converter" />
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\CompositeFieldProvider" />
<type name="Magento\Elasticsearch\Model\Config">
<arguments>
<argument name="engineList" xsi:type="array">
<item name="elasticsearch" xsi:type="string">elasticsearch</item>
<item name="elasticsearch5" xsi:type="string">elasticsearch5</item>
</argument>
</arguments>
</type>

<virtualType name="Magento\Elasticsearch\Model\Layer\Search\Context" type="Magento\Catalog\Model\Layer\Search\Context">
<arguments>
Expand Down
56 changes: 0 additions & 56 deletions app/code/Magento/Elasticsearch6/Model/Config.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Search\Model\QueryInterface;
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
use Magento\Elasticsearch6\Model\Config;
use Magento\Elasticsearch\Model\Config;
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
use Magento\Search\Model\QueryResultFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SuggestionsTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp()
{
$this->config = $this->getMockBuilder(\Magento\Elasticsearch6\Model\Config::class)
$this->config = $this->getMockBuilder(\Magento\Elasticsearch\Model\Config::class)
->disableOriginalConstructor()
->setMethods(['isElasticsearchEnabled'])
->getMock();
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Elasticsearch6/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Elasticsearch\Model\Config">
<arguments>
<argument name="engineList" xsi:type="array">
<item name="elasticsearch6" xsi:type="string">elasticsearch6</item>
</argument>
</arguments>
</type>

<type name="Magento\Search\Model\Adminhtml\System\Config\Source\Engine">
<arguments>
<argument name="engines" xsi:type="array">
Expand Down Expand Up @@ -44,7 +52,7 @@
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch6\Model\Client\ElasticsearchFactory</item>
</argument>
<argument name="clientOptions" xsi:type="array">
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch6\Model\Config</item>
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch\Model\Config</item>
</argument>
</arguments>
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function setUp()
$contentManager = $this->getMockBuilder(\Magento\Elasticsearch\SearchAdapter\ConnectionManager::class)
->disableOriginalConstructor()
->getMock();
$this->clientMock = $this->getMockBuilder(\Magento\Elasticsearch\Model\Client\Elasticsearch::class)
$this->clientMock = $this->getMockBuilder(\Magento\Elasticsearch6\Model\Client\Elasticsearch::class)
->disableOriginalConstructor()
->getMock();
$contentManager
Expand Down Expand Up @@ -78,7 +78,7 @@ protected function setUp()

/**
* @magentoAppIsolation enabled
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix adaptertest
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
use Magento\Elasticsearch\Model\Client\Elasticsearch as ElasticsearchClient;
use Magento\Elasticsearch6\Model\Client\Elasticsearch as ElasticsearchClient;
use Magento\Elasticsearch\Model\Config;
use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver;

Expand Down Expand Up @@ -95,7 +95,7 @@ private function search($text)
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix composite_product_search
*/
public function testSearchConfigurableProductBySimpleProductName()
Expand All @@ -104,7 +104,7 @@ public function testSearchConfigurableProductBySimpleProductName()
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix composite_product_search
*/
public function testSearchConfigurableProductBySimpleProductAttributeMultiselect()
Expand All @@ -113,7 +113,7 @@ public function testSearchConfigurableProductBySimpleProductAttributeMultiselect
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix composite_product_search
*/
public function testSearchConfigurableProductBySimpleProductAttributeSelect()
Expand All @@ -122,7 +122,7 @@ public function testSearchConfigurableProductBySimpleProductAttributeSelect()
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix composite_product_search
*/
public function testSearchConfigurableProductBySimpleProductAttributeShortDescription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
use Magento\Elasticsearch\Model\Client\Elasticsearch as ElasticsearchClient;
use Magento\Elasticsearch6\Model\Client\Elasticsearch as ElasticsearchClient;
use Magento\Elasticsearch\Model\Config;
use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver;
use Magento\Indexer\Model\Indexer;
Expand Down Expand Up @@ -87,7 +87,7 @@ protected function setUp()
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
* @return void
*/
Expand All @@ -106,7 +106,7 @@ public function testReindexAll(): void

/**
* @magentoAppIsolation enabled
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
* @return void
*/
Expand All @@ -131,7 +131,7 @@ public function testReindexRowAfterEdit(): void
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
* @return void
*/
Expand Down Expand Up @@ -170,7 +170,7 @@ public function testReindexRowAfterMassAction(): void
}

/**
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
* @magentoAppArea adminhtml
* @return void
Expand All @@ -192,7 +192,7 @@ public function testReindexRowAfterDelete(): void
/**
* @magentoDbIsolation enabled
* @magentoAppArea adminhtml
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
* @magentoDataFixture Magento/Elasticsearch/_files/configurable_products.php
* @return void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function setUp()
/**
* Test search of all products after full reindex
*
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest_configurable
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
*/
Expand All @@ -82,7 +82,7 @@ public function testSearchAll()
/**
* Test search of specific product after full reindex
*
* @magentoConfigFixture default/catalog/search/engine elasticsearch
* @magentoConfigFixture default/catalog/search/engine elasticsearch6
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest_configurable
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
*/
Expand Down
Loading

0 comments on commit f3d7a0d

Please sign in to comment.