In Magento, You can get the value of the current enable search engine value programmatically.
You can set Search engine from the admin panel
Settings -> Configuration -> Catalog -> Catalog -> Catalog Search -> Search Engine.
To Retrieve the Current search engine value programmatically by interface, Magento\Framework\Search\EngineResolverInterface
<?php namespace Jesadiya\CurrentSearchEngine\Model; use Magento\Framework\Search\EngineResolverInterface; class SearchEngine { /** * @var EngineResolverInterface */ private $engineResolver; public function __construct( EngineResolverInterface $engineResolver ) { $this->engineResolver = $engineResolver; } /** * @return string */ public function getCurrentUsedSearchEngine(): string { return $this->engineResolver->getCurrentSearchEngine(); } }
Get value by the given syntax,
$usedSearchEngine = $this->getCurrentUsedSearchEngine();
If you are on Magento 2.4 and don’t made any changes, your output will be elasticsearch7.
Elasticsearch7 is the Default Search Engine from the Magento 2.4
Output:
elasticsearch7