Skip to content

Discovery

A header search dropdown for Magento 2 stores on Hyvä with ElasticSuite that finds what customers mean while they are still typing: products, categories and attribute options (such as brands) matched from the first letters of any word and from inside words, ranked by relevance, in a dropdown that switches between two columns and one to fit the space it has.

  • Matches from the first letters. ElasticSuite’s own autocomplete builds its prefixes from word stems, so a partly typed word often finds nothing: on a stock store, “jack”, “wat” or “fitn” return no products and no categories until the word is complete. Discovery indexes the prefixes of the actual words, without stemming, so “jack” finds Jackets, “wat” finds Watches, “fitn” finds Fitness Equipment — and short words whose stem would be dropped from the index are found too.
  • Matches inside words (optional, on by default): “acket” finds “Jacket”, a name fragment finds the full name. Words that start with the typed text always rank first.
  • Ranked by relevance. Each searched field has its own weight (e.g. name above author); the best match is first.
  • Products, categories and attribute options. Products follow the store’s search rules exactly as on the results page (visible in search, stock display setting, ElasticSuite’s search blacklist and category permissions). Categories respect ElasticSuite’s Display in Autocomplete and show their parent path, so two “Jackets” under “Women” and “Men” can be told apart. Attribute options (brands, collections, any select attribute you choose) appear only when they have products visible in search, with their product count.
  • A dropdown that fits. Two columns (products left, categories and attributes right) when the dropdown is wide, one column on mobile or in a narrow header; the number of products is set separately for each. Keyboard navigation (arrows, Enter, Escape) with full ARIA combobox semantics.
  • Hyvä-native and CSP-ready. Alpine.js component registered with Alpine.data(), templates free of inline scripts, styles and JavaScript expressions — verified under Alpine’s CSP build. Plain CSS with custom properties: no Tailwind rebuild needed, and the accent follows the theme’s --color-primary.
  • Safe to switch off. Disabled for a store view, the header search reverts to the ElasticSuite autocomplete of the Hyvä compatibility module, unchanged.
  • Extensible. Add your own suggestion source (authors, stores, blog posts…) with one class and a few lines of di.xml; change how prices are computed with a preference.
Magento Open Source / Adobe Commerce 2.4.8 (tested on 2.4.8-p5) or 2.4.9
ElasticSuite 2.11.13 or newer on Magento 2.4.8 (tested on 2.11.21.1); 2.12.x on Magento 2.4.9
Search engine OpenSearch 2.x or 3.x (tested on OpenSearch 2.19), as supported by your ElasticSuite version
Hyvä Theme 1.3 or newer (tested on 1.5.3), with hyva-themes/magento2-smile-elasticsuite
PHP 8.3 – 8.4

Luma storefronts are not supported. hyva-themes/magento2-theme-module and hyva-themes/magento2-smile-elasticsuite come from Hyvä’s own Composer repository, which every Hyvä store already has configured.

Add the repository you received with your license to composer.json (once), then:

Terminal window
composer require slova/module-discovery:^2.0
bin/magento module:enable Slova_Discovery
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode
bin/magento cache:flush
bin/magento indexer:reindex catalogsearch_fulltext elasticsuite_categories_fulltext

The reindex adds the prefix and inside-word subfields to the product and category indices; until it has run, the dropdown stays empty. Discovery takes over Hyvä’s header search right away — there is nothing to place in the theme.

Terminal window
composer update slova/module-discovery
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode
bin/magento cache:flush
bin/magento indexer:reindex catalogsearch_fulltext elasticsuite_categories_fulltext

Read CHANGELOG.md first; settings are kept across versions.

Terminal window
bin/magento module:uninstall Slova_Discovery --remove-data
bin/magento indexer:reindex catalogsearch_fulltext elasticsuite_categories_fulltext

--remove-data deletes the module’s settings (slova_discovery/*). The module creates no tables. The reindex removes the extra subfields from the search indices.

Stores > Configuration > Slova > Discovery. All settings except Prefix Matching can be set per store view.

Setting Default
Enabled Yes Off: the header search shows ElasticSuite’s own autocomplete.
Minimum Characters 3 Characters typed before suggestions are requested.
Setting Default
Maximum Products on Wide Screens 8 Products shown when the dropdown has two columns. 0 hides products there.
Maximum Products on Narrow Screens 5 Products shown when it has one column (mobile, narrow header). 0 hides products there.
Second Line Attribute — Text or option attribute shown under the product name, e.g. brand or author.
Show Thumbnail / Price / SKU Yes / Yes / No

Whether the dropdown is “wide” depends on its own width (720 px), not on the screen: a narrow header search on a desktop uses the narrow-screen number.

Setting Default
Suggest Categories Yes Only categories with ElasticSuite’s Display in Autocomplete enabled, active, under the store’s root.
Maximum Categories 4
Setting Default
Suggested Attributes — Merchant-defined select/multiselect attributes (and Manufacturer) whose options are suggested — typically the brand.
Maximum Options per Attribute 5 Options with the most products first.

An option links to the search results page filtered on it.

These settings shape the search index: reindex catalogsearch_fulltext and elasticsuite_categories_fulltext after changing them.

Setting Default
Product Fields Product Name (10), SKU (5) Text attributes matched by the beginning of each typed word, with their weight. A higher weight ranks matches on that field first. Category names are always prepared.
Match Inside Words Yes Also matches fragments inside words, from 3 letters on. Makes the index larger: on very large catalogs, check the index size after the reindex.
Minimum Prefix Length 2 Shorter words are not indexed for prefix matching.
Maximum Prefix Length 20 Typed words longer than this do not match.
  • Products match when any significant typed word starts (or occurs inside) a word of a configured field. Words of one or two letters are left out when longer words were typed — in most languages they are function words that would match nearly every product. Results are ranked by score: field weight × how well the words match, with matches at the start of a word counting double.
  • Categories match when every typed word starts (or occurs inside) a word of the name, so a common word does not pull in unrelated categories.
  • Attribute options match on their store-view label (falling back to the admin label): at the start of a word, or anywhere in the label with Match Inside Words on.
  • Accents and case are ignored (“cafe” finds “Café”).
  • Search terms are not stemmed: “jackets” does not find “jacket” unless “jacket” is a prefix of it. Typo tolerance is left to the search results page.

The dropdown is styled by view/frontend/web/css/discovery.css through custom properties on .sd-root:

Property Default
--sd-accent var(--color-primary, #1d4ed8)
--sd-text / --sd-muted #111827 / #6b7280
--sd-border / --sd-hover #e5e7eb / #f3f4f6
--sd-bg / --sd-side-bg #fff / #fafafa
--sd-radius .375rem

Override them (or any .sd-* rule) in the theme. Templates can be overridden as usual:

  • Slova_Discovery::search/form.phtml — the search form and the dropdown frame
  • Slova_Discovery::search/section/products.phtml, links.phtml, chips.phtml — one per section type

The component is registered as slovaDiscovery in view/frontend/web/js/discovery.js; templates may use its properties and argument-less methods only (Alpine CSP build).

Implement Slova\Discovery\Api\SuggestionProviderInterface and register it in di.xml:

class StoreLocatorProvider implements \Slova\Discovery\Api\SuggestionProviderInterface
{
public function getSections(\Slova\Discovery\Model\Suggestion\SearchContext $context): array
{
$items = []; // e.g. [['label' => 'Downtown store', 'url' => 'https://…']]
return [new \Slova\Discovery\Model\Suggestion\Section('stores', 'links', (string) __('Stores'), $items)];
}
}
<type name="Slova\Discovery\Model\Suggestion\ProviderPool">
<arguments>
<argument name="providers" xsi:type="array">
<item name="stores" xsi:type="array">
<item name="provider" xsi:type="object">Vendor\Module\Model\StoreLocatorProvider</item>
<item name="sortOrder" xsi:type="number">25</item>
</item>
</argument>
</arguments>
</type>

Built-in providers: attributes (10), categories (20), products (30). A provider that throws is logged and skipped; the others still answer.

Section types products, links (label, url, optional path) and chips (label, url, count) have templates already. For a new type, map a template to it in the layout — type names must be plain identifiers:

<referenceBlock name="header-search">
<arguments>
<argument name="section_renderers" xsi:type="array">
<item name="stores" xsi:type="string">Vendor_Module::discovery/stores.phtml</item>
</argument>
</arguments>
</referenceBlock>

products sections fill the main (left) column; every other type goes to the side column.

Prices come from Magento’s price model (catalog price rules, tax display settings, “from” prices for bundles and configurables). For other rules, add a preference for Slova\Discovery\Api\ProductPriceResolverInterface returning the final and regular price in the current store currency.

  • The dropdown stays empty. Reindex catalogsearch_fulltext and elasticsuite_categories_fulltext (the subfields are added at indexing time), then check that Enabled is on for the store view and that the typed text reaches Minimum Characters.
  • New settings in Prefix Matching have no effect. They apply at indexing time: reindex.
  • No categories. Check ElasticSuite’s Display in Autocomplete on the categories.
  • No attribute options. Options are shown only when at least one product with the option is visible in search.
  • Production mode, after installing or upgrading. Run setup:di:compile; without it, new classes are not wired.
  • Designed for the Hyvä header search (header-search block, input #search); one Discovery search per page.
  • No suggestions of past search terms, and no typo tolerance in the dropdown (the results page keeps ElasticSuite’s spellchecking).
  • Inside-word matching starts at 3 letters.

Proprietary software, licensed per the agreement accepted at purchase — see LICENSE. Support: through the channel listed in your license.