Skip to content
intermediate Phase 70 · Search System

Search Indexes — Product, Category, and Suggestions

Understanding search indexes in Magento 2: product index, category index, search suggestions, synonyms, and index management

45m
1 problems
Topic Progress 0%

Product Search Index

Product Index Structure

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

Indexed Product Data

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

Reindexing Product Index

# Full reindex
php bin/magento indexer:reindex catalogsearch_fulltext

# Check status
php bin/magento indexer:status catalogsearch_fulltext

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

Product Index Data Flow

// Product save triggers index update
public function afterSave()
{
    parent::afterSave();
    // In schedule mode: mark as invalid
    // In real-time: reindex immediately
}

Searchable Attributes

// Check searchable attributes
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
$attributes = $eavConfig->getEntityAttributes('catalog_product');

foreach ($attributes as $attribute) {
    if ($attribute->getIsSearchable()) {
        echo $attribute->getAttributeCode() . PHP_EOL;
    }
}

Category Search Index

Category Index Purpose

Maps products to categories for filtered search:

-- Category-product mapping
CREATE TABLE catalog_category_product (
    category_id INT,
    product_id INT,
    position INT
);

Category Search Features

  • Filter search by category
  • Category-specific results
  • Category navigation in search

Category Reindex

# Reindex category mapping
php bin/magento indexer:reindex catalog_category_product

# Check status
php bin/magento indexer:status catalog_category_product

Category Configuration

// Enable category search
'catalog' => [
    'search' => [
        'enable_search' => 1,
        'search_in_category' => 1
    ]
]

Category Filter in Search

// Search within category
$query = $this->searchQueryFactory->create();
$query->setSearchParam('category_id', $categoryId);
$query->setSearchParam('q', $searchTerm);

Search Suggestions and Synonyms

Search Suggestions

// Enable suggestions
'catalog/search' => [
    'suggestion' => [
        'enabled' => 1,
        'max_suggestions' => 5
    ]
]

Autocomplete

// Autocomplete configuration
'catalog/search' => [
    'autocomplete' => 1,
    'max_count' => 10,
    'min_query_length' => 2
]

Synonyms

// Synonym configuration
// Admin: Marketing > Search Synonyms

// Example synonyms:
// laptop -> notebook, portable computer
// phone -> mobile, cellphone
// tv -> television, flat screen

Synonym Groups

// Group synonyms together
// laptop, notebook, portable computer
// phone, mobile, cellphone
// tv, television, flat screen

Search Term Management

// Track search terms
// Admin: Marketing > Search Terms

// See what users search for
// Identify missing products
// Add synonyms for popular terms

Index Optimization

Index Performance

# Check index size
mysql -u root -p -e "SELECT COUNT(*) FROM catalogsearch_fulltext;"

# Check index health
curl -X GET "http://localhost:9200/_cat/indices?v"

Optimization Techniques

// Batch reindex for large catalogs
$batchSize = 1000;
$productIds = range(1, 100000);

$chunks = array_chunk($productIds, $batchSize);
foreach ($chunks as $chunk) {
    $indexer->reindexList($chunk);
}

Index Monitoring

-- Check reindex status
SELECT indexer_id, status, updated_at
FROM indexer_state
WHERE indexer_id = 'catalogsearch_fulltext';

-- Check index size
SELECT
    table_rows,
    data_length,
    index_length
FROM information_schema.TABLES
WHERE table_name = 'catalogsearch_fulltext';

Best Practices

  1. Use real-time mode for small catalogs
  2. Use schedule mode for large catalogs
  3. Monitor index health regularly
  4. Batch reindex for bulk operations
  5. Clean stale search terms periodically

Practice Problems

0 / 1 solved
Search Index Optimization

A store with 200k products has slow search reindex. Optimize the indexing process.

Quiz

1. What does the product search index contain?

Question 1 options

2. What is the search synonym feature?

Question 2 options

3. How do you check searchable attributes?

Question 3 options

4. What is the benefit of category search index?

Question 4 options

Flashcards

Question

What does product search index contain?

Answer

Name, SKU, description, and searchable attributes

Question

What are search synonyms?

Answer

Related terms mapped together (laptop -> notebook)

Question

How to reindex search?

Answer

php bin/magento indexer:reindex catalogsearch_fulltext

Question

What does category index enable?

Answer

Filtering search results by specific categories

Question

What is autocomplete?

Answer

Real-time search suggestions as user types

Revision Notes

Key Takeaways

  • 1. Product search index contains name, SKU, description, and searchable attributes
  • 2. Category index maps products to categories for filtered search
  • 3. Synonyms map related terms together for better search UX
  • 4. Autocomplete provides real-time search suggestions
  • 5. Use batch reindex for large catalogs
  • 6. Monitor index health and size regularly

Interview Tips

  • Explain what data is included in search indexes
  • Describe how synonyms improve search UX
  • Discuss search index optimization strategies
  • Know how to monitor search index health

Cheat Sheet

Search Indexes Cheat Sheet

Product index:

  • name, sku, description, searchable attributes
  • Table: catalogsearch_fulltext

Category index:

  • product-category mapping
  • Enables filtered search

Synonyms:

  • laptop -> notebook, portable computer
  • Config: Marketing > Search Synonyms

Reindex:
php bin/magento indexer:reindex catalogsearch_fulltext

Monitor:

  • indexer:status catalogsearch_fulltext
  • mysql: SELECT from catalogsearch_fulltext
  • curl: localhost:9200/_cat/indices