Skip to content
intermediate Phase 70 · Search System

Search Introduction — Catalog Search Architecture

Understanding Magento 2 search system: catalog search, search engine integration, search architecture, and search configuration

45m
1 problems
Topic Progress 0%

Magento Search Architecture

Search Flow

User Query -> Search Controller -> Search Engine -> Results -> Response
  1. User submits search term
  2. Search controller processes request
  3. Query sent to search engine (OpenSearch/Elasticsearch)
  4. Search engine returns matching products
  5. Results ranked and displayed

Search Components

CatalogSearch
├── Fulltext Search
├── Synonyms
├── Autocomplete
├── Search Suggestions
└── Search Results Page

Search Types

Type Description
Full-text Natural language search across attributes
Exact Match Exact SKU or attribute match
Category Search within specific category
Advanced Multi-attribute search

Search Engine Options

Engine Magento Support
OpenSearch Recommended (Magento 2.4+)
Elasticsearch Supported
MySQL Deprecated
Algolia Extension only

Search Engine Integration

OpenSearch/Elasticsearch Configuration

// app/etc/env.php
return [
    'catalog' => [
        'search' => [
            'engine' => 'elasticsearch8',
            'engine_config' => [
                'host' => 'localhost',
                'port' => '9200',
                'index' => 'magento2'
            ]
        ]
    ]
];

CLI Configuration

php bin/magento setup:config:set \
    --search-engine=elasticsearch8 \
    --elasticsearch-host=localhost \
    --elasticsearch-port=9200 \
    --elasticsearch-index-prefix=magento2

Search Engine Setup

# Check search engine status
php bin/magento search-engine:status

# Test connection
php bin/magento search-engine:test

# Create index
php bin/magento search-engine:create

Search Configuration

<!-- system.xml -->
<field id="engine" translate="label" type="select" sortOrder="10">
    <label>Search Engine</label>
    <source_model>Magento\Search\Model\Adminhtml\System\Config\Source\Engine</source_model>
</field>

Fulltext Search Index

What Fulltext Index Contains

-- Fulltext index table
CREATE TABLE catalogsearch_fulltext (
    product_id INT,
    store_id INT,
    data_index TEXT,
    PRIMARY KEY (product_id, store_id)
);

Indexed Fields

  • Product name
  • SKU
  • Description
  • Short description
  • Custom attributes (searchable)

Reindexing Search

# Full reindex
php bin/magento indexer:reindex catalogsearch_fulltext

# Check status
php bin/magento indexer:status catalogsearch_fulltext

# Set mode
php bin/magento indexer:set-mode realtime catalogsearch_fulltext

Searchable Attributes

// Mark attribute as searchable
$eavSetup->addAttribute(
    'catalog_product',
    'custom_field',
    [
        'type' => 'text',
        'label' => 'Custom Field',
        'searchable' => true,  // Enable search
        'filterable' => false,
        'comparable' => false
    ]
);

Search Performance

// Default search configuration
'search' => [
    'max_execution_time' => 3,  // seconds
    'minimum_should_match' => '75%',
    'fuzziness' => 'AUTO'
]

Search Configuration

Search Settings

<!-- system.xml -->
<section id="catalog">
    <group id="search">
        <field id="engine" type="select">
            <label>Search Engine</label>
        </field>
        <field id="min_query_length">
            <label>Minimum Query Length</label>
        </field>
        <field id="max_query_length">
            <label>Maximum Query Length</label>
        </field>
    </group>
</section>

Synonyms Configuration

// Admin: Marketing > Search Synonyms
// Add synonyms:
// laptop -> notebook, portable computer
// phone -> mobile, cellphone

Autocomplete Configuration

// Enable autocomplete
'catalog/search' => [
    'autocomplete' => 1,
    'max_count' => 10
]

Search Rules

// Search behavior rules
'search' => [
    'use_url_in_product_search' => 1,
    'weighted_search' => 1,
    'max_count_search_results' => 10
]

Debug Search

# Check search configuration
php bin/magento config:show catalog/search

# Test search query
php bin/magento search:query "test product"

# Check search index
php bin/magento search-engine:status

Practice Problems

0 / 1 solved
Search Performance Issue

Search results are slow and incomplete. Diagnose the search configuration and indexing issues.

Quiz

1. What is the recommended search engine for Magento 2.4+?

Question 1 options

2. What command reindexes the search index?

Question 2 options

3. How do you make an attribute searchable?

Question 3 options

4. What file configures search engine settings?

Question 4 options

Flashcards

Question

What is the recommended search engine?

Answer

OpenSearch/Elasticsearch for Magento 2.4+

Question

How to reindex search?

Answer

php bin/magento indexer:reindex catalogsearch_fulltext

Question

How to make attribute searchable?

Answer

Set searchable=true in attribute EAV setup

Question

Where is search configured?

Answer

app/etc/env.php under catalog.search

Question

What is fulltext search?

Answer

Natural language search across product attributes like name, SKU, description

Revision Notes

Key Takeaways

  • 1. Magento search uses OpenSearch/Elasticsearch as the recommended engine
  • 2. Fulltext index contains product name, SKU, description, and searchable attributes
  • 3. Configure search engine in env.php under catalog.search
  • 4. Mark attributes as searchable in EAV setup
  • 5. Reindex with indexer:reindex catalogsearch_fulltext
  • 6. Use synonyms and autocomplete for better search UX

Interview Tips

  • Explain the Magento search architecture and flow
  • Describe how fulltext indexing works
  • Discuss search engine configuration options
  • Know how to debug search issues

Cheat Sheet

Search Introduction Cheat Sheet

Search flow:
User Query -> Controller -> Search Engine -> Results

Engine: OpenSearch/Elasticsearch

Config:

'catalog' => ['search' => [
    'engine' => 'elasticsearch8',
    'engine_config' => ['host' => 'localhost', 'port' => '9200']
]]

Reindex:
php bin/magento indexer:reindex catalogsearch_fulltext

Searchable attribute:
'searchable' => true in EAV setup

Check:
search-engine:status