Skip to main content

Search Functionality

This document describes all searching capabilities in the ecommerce platform: how search works for customers and staff, what Elasticsearch is used for, what can be searched, how results stay up to date, and which console commands / cron jobs support search.

It focuses on behaviour and functionality, not low-level implementation details. For indexing internals, see also Elasticsearch Spool and Elasticsearch Reliability Plan.


1. Overview

Customer-facing catalog search is powered by Elasticsearch.

RoleSystem
Source of truthMySQL database (products, categories, authors, etc.)
Search engineElasticsearch (fast full-text search, filters, autocomplete, facets)
How they stay in syncChange queue (“spool”) + cron command that pushes updates to Elasticsearch

When a customer types in the search box or browses with filters, the storefront API queries Elasticsearch — not MySQL — for catalog results.

Admin product grids and most back-office filters use MySQL. Product edits in admin still flow into Elasticsearch through the spool, so storefront search reflects those changes after the next spool run.


2. What Can Be Searched

Elasticsearch holds dedicated indexes for these entities:

WhatUsed for
ProductsMain catalog search, product lists, filters, sorting
CategoriesCategory listing and autocomplete
Authors / product personsAuthor pages, author search, autocomplete
PublishersPublisher browse, autocomplete
SeriesBook series browse, autocomplete
Product listsCurated collections
Campaign listsCampaign / promotional product groupings

Product documents also carry related data used during search, for example:

  • Title and alternative names / tags
  • ISBN / EAN and related identifiers
  • Categories, authors, publisher, series
  • Prices, discounts, availability, stock, delivery time
  • Product type (book, ebook, audiobook, tech, game, …)
  • Language, binding/cover type
  • Sales / popularity signals
  • Badges, images, web-store visibility flags

Not searched via Elasticsearch (examples): admin CRUD grids, blogs, events, orders, and partner feeds that use MySQL-only search models.


3. How Search Works (End to End)

Customer search flow

  1. Customer types a query or opens a category / list / filtered page.
  2. Storefront calls the API (autocomplete while typing; full search + filters for results).
  3. API checks whether Elasticsearch is available.
    • If unavailable → search is reported as temporarily down (see Section 11).
  4. Request is scoped to the current web store and client account (B2C / B2B visibility, inactive integrations filtered out).
  5. Elasticsearch returns matching products (and related suggestions for autocomplete).
  6. API returns paginated results, facets, and sort options to the storefront.

Keeping the search index up to date

Product / category / author / etc. is created, updated, or deleted

Change is queued automatically (spool table)

Cron runs: php yii elastic/spool

Queued items are sent to Elasticsearch in batches

Storefront search starts reflecting the change

Updates are near real-time (typically within a few minutes of the spool cron), not instantaneous on every save.


4. Autocomplete (Search-as-You-Type)

Autocomplete helps customers find products and related entities while typing.

Main endpoint

EndpointPurpose
GET /autocompleteUnified suggestions (preferred)
GET /product/autocompleteLegacy / deprecated product autocomplete

Also available in specialized modules:

EndpointModule
Audio module /autocompleteAudiobook-oriented suggestions
Ebook module /autocompleteEbook-oriented suggestions

What autocomplete returns

For a search term, suggestions can include:

  • Products
  • Authors
  • Publishers
  • Series
  • Categories (limited)
  • Tags (from product alternative names / search tags)

Behaviour notes

  • Input is the search term (older product autocomplete may use search).
  • Optional limits: product count, related-entity count, product type filter.
  • If the term looks like an ISBN / EAN, autocomplete focuses on the exact product match and skips related-entity / tag suggestions.
  • Products from inactive integration sources are excluded.
  • Suggestions prefer products that are easier to buy (e.g. better availability, image present, stronger sales) and push out-of-stock items lower.

Main endpoint

EndpointPurpose
GET /product/searchFull product search with filters, sort, and pagination

Requires the store header (web store code, e.g. WEB / WEB2).

What customers can search by

CapabilityDescription
Free-textMatches title, tags/synonyms, authors, and related text (including cross-field matches like author + title in any order)
ISBN / EANIf the query looks like an identifier, search treats it as an exact product lookup
Author nameDedicated author text filter
Publisher nameDedicated publisher text filter
Series nameDedicated series text filter

Filters

Filter areaExamples
CategoryCategory ID, subcategory IDs, NAV codes, slug + level
PeopleAuthor / person ID(s)
PublisherPublisher ID(s)
SeriesSeries ID(s)
ListsProduct list ID, campaign list ID (default sort can keep manual list order)
Product typeBook, ebook, audiobook, tech, game, etc. (type / productType)
Cover / bindingCover type or multiple cover types
LanguageET / EN / RU, or "other" for languages outside the main app languages
PriceMinimum and maximum price
DiscountMinimum discount percent
AvailabilityWeb, in-shop, coming soon, out of stock, or specific shop codes
OtherPreorder flag, new-products list, category “top” interval (e.g. 7 / 30 / 360 days), EAN

Sorting

Customers can sort results by options such as:

  • Relevance (default ranking — see Section 8)
  • Price (asc / desc)
  • Discount percent
  • Name
  • Newest / created date
  • Sales / popularity
  • Category “top” ranking
  • Manual sequence when browsing curated product / campaign lists

Pagination

  • Default page size: 20
  • Maximum page size: 100
  • Standard pagination headers (X-Pagination-*) are used

Query safeguards

  • Very long text queries are truncated so search stays stable.
  • Overly complex queries may return an empty product list rather than failing the whole API.

6. Dynamic Filters (Facets)

Dynamic filters show filter options with product counts for the current search context (so customers see only relevant authors, publishers, etc.).

Endpoints

EndpointPurpose
GET /product-dynamic-filter/filtersAll main facets for the current search/filter context
GET /product-dynamic-filter/search-authorSearch within author facet options (+ product counts)
GET /product-dynamic-filter/search-seriesSearch within series facet options (+ product counts)
GET /product-dynamic-filter/search-publisherSearch within publisher facet options (+ product counts)

Facet types typically included

  • Categories
  • Authors
  • Binding / cover types
  • Publishers
  • Series

Facet endpoints use the same filter parameters as product search, so counters stay consistent with the result list.


Besides product search and autocomplete, the API exposes Elasticsearch-backed listing/search for related entities:

EndpointWhat it searches
GET /category/searchCategories
GET /product-person/searchAuthors / product persons
GET /author/searchAuthors (author-oriented API)
GET /product-publisher/searchPublishers
GET /product-series/searchSeries
GET /product-list/searchProduct lists
GET /campaign-list/searchCampaign lists

These power browse pages and entity directories on the storefront.


8. How Results Are Ranked

Default product ranking is designed so that useful, buyable products appear first.

Functional ranking behaviours include:

BehaviourEffect for customers
Title matchesStronger than tag / synonym matches
Author matchesAuthors contribute to relevance
Cross-field matchingQueries like “Rowling Harry” can still find the right title
Typo toleranceSmall spelling mistakes can still match
Character / spacing flexibilityAccent / spacing differences are handled more forgivingly
Sales / popularityBetter-selling products get a boost
ImagesProducts with a thumbnail are preferred in suggestions
Delivery / availabilityFaster / available products are preferred
Out of stock / coming soonPushed lower in the list
Product sourcePreferred sources (e.g. manual / NAV) can rank above weaker integration sources

There is no geo / location-based search.


9. Synonyms, Tags & Search Enrichment

Search matching is improved beyond the product title alone.

Manual search tags

  • Staff can manage product tags (alternative names) in admin Search settings.
  • Tags are stored on the product and indexed into Elasticsearch.
  • They help customers find products using alternate wording, nicknames, or common misspellings.

Admin area: Search settings (admin → setting Search controller) — used to add tags that later appear in storefront search/autocomplete.

AI search synonyms

  • Non-book products can receive AI-generated synonym / typo-helper strings.
  • These are stored on the product and merged into searchable alternative names when indexing.
  • Generation is done via a console command (not a customer-facing feature):
php yii product-ai-search-synonyms/generate-batch
php yii product-ai-search-synonyms/verify

Optional synonym analyzer

  • An index-level synonym search mode can be enabled via configuration (enableSynonymSearch).
  • Enabling it for live use requires rebuilding product mappings / reindex (typically via product import commands). Treat this as an ops-controlled feature.

10. Index Sync, Commands & Cron Jobs

Automatic change tracking

When these entities change, they are queued for Elasticsearch update:

  • Products
  • Categories
  • Authors / product persons
  • Publishers
  • Series
  • Product lists
  • Campaign lists

Related product changes (e.g. images, badges) can also trigger re-queueing so search documents stay complete.

Queued actions are essentially: save / update, delete, or full index.

Cron job (incremental updates)

ItemDetail
Commandphp yii elastic/spool
ScheduleFrequent — every few minutes
PurposeProcess queued search index updates
Documented inCron Jobs, Elasticsearch Spool

This is the main job that keeps storefront search fresh after catalog changes, imports, and admin edits.

Elasticsearch console commands

CommandWhat it does
php yii elastic/spoolProcess the queue (normal ongoing sync). Skips work if Elasticsearch is down.
php yii elastic/importFull reindex of all search indexes (prompts for confirmation; use --noPrompt=1 when automating)
php yii elastic/import-upgradeFull import used during Elasticsearch cluster upgrades
php yii elastic/import-productsReindex products only
php yii elastic/import-product-personsReindex authors / persons only
php yii elastic/import-publishersReindex publishers only
php yii elastic/import-seriesReindex series only
php yii elastic/import-categoriesReindex categories only
php yii elastic/add-items-to-spoolManually queue specific record IDs for indexing

Controller: console/controllers/ElasticController.php.

Health & monitoring commands

CommandWhat it does
php yii health-check/elasticsearchChecks cluster health; can alert if Elasticsearch is down or the spool lock looks stuck
php yii health-check/elasticsearch --notify=0Check only (no email notification)
php yii daily-report/healthDaily ops health report (includes Elasticsearch / spool status)

Recommended ops cadence for the Elasticsearch health check is frequent (about every 1–2 minutes) so downtime is noticed quickly.

When to use which command

SituationWhat to run
Normal day-to-dayCron already runs elastic/spool
After bulk catalog changesWait for spool, or selectively reindex the affected entity type
After mapping / analyzer changesFull or product reindex (elastic/import / elastic/import-products)
After DB restoreRebuild search indexes with elastic/import (see also BACKUPS.md)
Suspected stuck queue / ES issueshealth-check/elasticsearch, then fix ES and run elastic/spool

11. When Search Is Unavailable

If Elasticsearch is down or degraded, catalog search does not silently return empty results.

SignalValue
HTTP status503
Response headerX-Search-Available: 0
MessageSearch is temporarily unavailable. Please try again shortly.

This applies to product search, autocomplete, dynamic filters, and other Elasticsearch-backed listing endpoints.

Important points:

  • There is no MySQL full-text fallback for storefront catalog search.
  • The frontend can detect the header and show a “search temporarily unavailable” state.
  • While Elasticsearch is unhealthy, elastic/spool skips processing so the queue does not thrash.
  • Staging can force this degraded mode for QA (forceSearchUnavailable query/header when allowed in config). Keep that disabled in production.

Details: Elasticsearch Reliability Plan.


12. Search Surfaces by Area

AreaUses Elasticsearch?Purpose
Storefront APIYesCustomer catalog search, autocomplete, facets, entity browse
Hotline (in-store)YesIn-store product lookup UI for shop staff (hotline Search)
Admin product gridsNo (MySQL)Staff filtering and management
Admin Search settingsIndirectManage tags that later feed Elasticsearch
Audio / Ebook modulesYes (autocomplete / product search variants)Format-specific storefront experiences
Stacc / partner product feedsNo (MySQL)Partner recommendation/export flows — not catalog ES search

13. Feature Summary Checklist

Storefront search supports:

  • Product full-text search (title, tags/synonyms, authors, cross-field)
  • Autocomplete across products and related entities
  • ISBN / EAN exact lookup
  • Category, author, publisher, series, type, language, cover filters
  • Price and discount range filters
  • Availability and shop-based availability filters
  • Curated product / campaign list browsing with sequence
  • Dynamic facets with counters
  • Multiple sort options + relevance ranking
  • Typo-tolerant / flexible matching
  • Manual tags and AI search synonyms
  • Web-store and client-account scoping
  • Hotline in-store search
  • Near-real-time index sync via spool + cron
  • Full and selective reindex commands
  • Explicit unavailable mode when Elasticsearch is down

Does not include:

  • Geo / location-based product search
  • MySQL fallback for catalog search during Elasticsearch outages
  • Elasticsearch-backed admin product management grids

DocumentContents
Elasticsearch SpoolIndexing pipeline, spool table, providers, recovery
Elasticsearch Reliability Plan503 contract, force-degrade QA, health checks
Cron JobsScheduled elastic/spool and other jobs
Console CommandsConsole command index
BackupsRebuilding Elasticsearch after DB restore
External IntegrationsImports → spool → search index
Admin ModuleAdmin changes flowing into search via spool
API DocumentationHigh-level API notes (autocomplete / lists)
Gap: OP-004 Search FunctionalityGap tracker view of this topic

# Ongoing index updates (also run by cron)
php yii elastic/spool

# Full rebuild of all search indexes
php yii elastic/import --noPrompt=1

# Selective rebuilds
php yii elastic/import-products
php yii elastic/import-product-persons
php yii elastic/import-publishers
php yii elastic/import-series
php yii elastic/import-categories

# Health
php yii health-check/elasticsearch
php yii health-check/elasticsearch --notify=0

# AI synonyms for non-book products
php yii product-ai-search-synonyms/generate-batch
php yii product-ai-search-synonyms/verify