Indexing and search
A site holds two indexes with two different jobs, and a question about "the index" is really a question about which one. Getting them apart is most of this page.
| Content index | Search index | |
|---|---|---|
| Answers | filters, ordering and facet counts of a listing | free-text queries and autocomplete |
| Unit | one row per value of a declared field, per record | one document per searchable page |
| Shape comes from | the template's field declarations | the theme's search layout, for the matched text |
| Written | in the same transaction as the record save | rebuilt in the background after a save |
| Read by | GET/POST …/query listings, GET …/filters |
POST /api/search, GET /search/suggest |
Selecting content with the filter language is Selecting content; this page is about what makes a path exist in the first place, and about the text search beside it.
Declaring a field for the content index
A field is filterable, sortable and countable only if its declaration says so. The declaration is
an index entry on the template's field record:
[
{ "name": "headline", "fieldTemplate": "textEditorTemplate", "value": "" },
{
"name": "price",
"fieldTemplate": "numericEditorTemplate",
"value": 0,
"index": { "filter": true, "sort": true, "label": "Price" }
}
]
| Key | Meaning |
|---|---|
filter |
The path accepts conditions and contributes facet counts |
sort |
The path can be used in sort. Defaults to false |
type |
text, number, date or bool. Defaults from the field kind (below) |
multi |
One record holds several values for this path — a set, not one value. Defaults to false |
agg |
How several values fold into one sort key: min or max. Defaults to min, and to max on a multi date field |
label |
The name a filter panel shows for the path |
The default type follows the field kind, so it rarely needs saying: numericEditorTemplate and
integerEditorTemplate are number, dateEditorTemplate and dateTimeEditorTemplate are date,
checkboxEditorTemplate is bool, everything else is text.
Three consequences are worth knowing before you write the declarations:
- A field without an
indexentry is not indexed at all. Its path does not exist: a filter or a sort naming it is refused with the list of declared paths, and no facet counts come back for it. - A field of a part is addressed through its block —
parts.hero.heading. The declarations of a block reach the index only when the template names that block once; naming one block twice declares nothing. - Declarations live in
content. Thefieldsprojection a template read answers is meant for editors and carries noindexkey, so writing a declaration means writing the template'scontentstring (Building a template).
Keeping the content index fresh
A record's save writes its index rows in the same transaction as the record itself: rows for the record are replaced as a whole, so a listing or a facet count after the save answers from the data that was just written. There is no reindex step to wait for and no window in which a listing and a record disagree.
Changing a template is a different event, because the declarations themselves changed. Such a save moves the site's declaration version — a listing that catches the new version re-reads the declarations instead of serving the old set, so a path that no longer exists is refused rather than answered from a stale row — and it queues a repair pass that fills the values for the new declarations across the site. The repair pass runs by default on a production install; where it is switched off, a nightly pass repairs the site and each record's own save repairs that record — only later, and only for the records that get saved.
The panel a filter interface asks for
GET /api/pages/filters?siteId=<site-id> answers every filterable path of the surface with its
counts, and takes the same base filters a listing takes:
curl "$ADMIN_API/api/pages/filters?siteId=<site-id>" -b cookies.txt
The answer is { "success": true, "data": { "facets": [ … ] } }, each facet in the same shape a
listing's facets has. Blog posts and products answer the same call on their own resource.
What the search index holds
The search index is a set of documents, one per page a reader can open:
| Indexed | As |
|---|---|
| Pages | page |
| Blog posts | blogPost |
| Products | product |
| Catalog products | catalogProduct |
| Static pages | staticPage |
Reviews are indexed too, but not as documents of their own — a review has no page to open, so its text joins the product or the page it is about. Feeds and feed pages are not indexed: a feed is an export, and a feed page has nothing that says whether it is published.
A document carries its identifier, its type (on the wire, provider), its path, its title, the text
a query matches, and the facet values filters and sorting use. A request may name any of these keys
whatever the type; a document only matches on the values it actually carries:
| Key | Taken as | On a document of |
|---|---|---|
type |
a value or a list | any type |
category, tag |
a value or a list | products and catalog products |
vendor |
a value or a list | products |
price |
a "min..max" range, either bound open |
products and catalog products |
rating |
a "min..max" range |
products |
| a site's own facet field | a value or a list, or a range for a numeric field | products and catalog products |
Every document also carries its publication date — sort=newest orders by it — but it is not a
filter key.
A product template adds its own facets: a selection field (selectListEditorTemplate,
radioButtonsEditorTemplate, checkboxesEditorTemplate) becomes a multi facet and a numeric field
a range facet, as long as at least one product fills the field in. Those keys are the field names,
and they come back in facetDefinitions next to the standard set.
The matched text comes from the theme. A site that has a layout named search index layout
decides what a search can find by rendering each record through it; without such a layout the text
values of the record's view model are used instead. Static pages are the exception: they have no
view model to render, so their stored text is indexed as it stands. Either way the choice is
deliberate — the person who writes the theme knows what a reader will look for.
When the search index is rebuilt
Saving a page, a blog post, a product, a static page or a review clears the site's build stamp, in the same transaction. A background loop picks the site up — every 60 seconds by default — rebuilds the whole index for it, and stamps it again. Catalog products are indexed as well, but they are not written through this API, so no save of theirs clears the stamp: they change on the next rebuild that anything else asks for.
- Rebuilds are whole-site, and saves made during one are not lost: a stamp cleared mid-rebuild makes the next pass run again with the fresh data.
- Only published records become documents, so unpublishing removes a page from search results on the next rebuild.
POST /api/search/create-indexwith{ "siteId": "<site-id>" }clears the stamp without saving anything — that is how you ask for a rebuild on demand:
curl -X POST "$ADMIN_API/api/search/create-index" \
-H 'content-type: application/json' \
-b cookies.txt \
-d '{ "siteId": "<site-id>" }'
An engine that keeps the index inside the process — which is what a site runs on until the deployment configures an external engine — starts empty when the process starts, while the stored stamp still says the site is built. The platform accounts for that: on such an engine the stamp is a claim about a process that no longer exists, so the next pass of the rebuild loop rebuilds the site without being asked. Ask for a rebuild by hand when you want one sooner than the loop.
Tuning the index
Four values shape the index of one site, and a site is asked about them on its own resource:
| Key | Meaning | Default |
|---|---|---|
fieldWeights |
Which attributes count and how much — title=10,content=1 |
title=10,content=1 |
morphology |
Word-form handling: none, stem_en, stem_ru, stem_enru, lemmatize_en, lemmatize_ru, lemmatize_enru |
stem_ru |
minWordLen |
Shortest word that is indexed, 0…255 |
1 |
minPrefixLen |
Shortest prefix a wildcard search may use, 0…255 |
2 |
curl -X PUT "$ADMIN_API/api/sites/<site-id>/search-settings" \
-H 'content-type: application/json' \
-b cookies.txt \
-d '{ "fieldWeights": "title=15,content=1", "morphology": "stem_en" }'
GET on the same path answers the settings a site actually has, defaults filled in; a stored value
that does not validate answers the defaults with a warning rather than an error. PUT changes only
the keys it is given, and it clears the build stamp, so the index is rebuilt from the new
configuration.
Each of the four is validated before it reaches the engine — a weight that is not
attribute=number, a morphology outside the list, or a length outside 0…255 is refused with
400. GET /api/search/get-analyzers answers the analyzer names the platform offers; the settings
above are the knobs a site may set.
fieldWeights names attributes of the index, not field paths; title and content are the two the
document's text lives in.
Querying the search index
curl -X POST "$CONTENT_API/api/search" \
-H 'content-type: application/json' \
-d '{ "query": "brake pads", "page": 1, "hitsPerPage": 12, "sort": "relevance", "facets": ["category"] }'
| Key | Meaning |
|---|---|
query |
The words to match. An empty query is browse mode: filters and facets without text matching |
page |
One-based page, default 1 |
hitsPerPage |
Page size, 1…200. Default 24 |
sort |
relevance (default), newest, price_asc, price_desc, rating |
filters |
An object keyed by the facet keys above — a scalar or an array means "any of", a "min..max" string means a range. This is the search request's own object, not the filter[<path>] language of a listing |
facets |
Keys whose value counts come back with the answer. The standard keys are category, vendor, tag, type, price and rating; any other key is one of the site's own facet fields |
operator |
and (default) requires every word, or accepts any |
expandKeywords |
true expands the query words to their morphological forms. An engine capability, not a floor: an engine that matches literally ignores it |
The answer reports the window it used and the hits with a sample of the matched text:
{
"query": "brake pads",
"page": 1,
"hitsPerPage": 12,
"nbHits": 3,
"nbPages": 1,
"hits": [
{
"id": "product:1e6f…",
"provider": "product",
"title": "Brake pad set, front",
"titleSample": "Brake pad set, front",
"path": "/parts/brake-pad-front",
"pathSample": "/parts/brake-pad-front",
"contentSample": "…front axle brake pads, 280 mm…"
}
],
"facets": { "category": { "brakes": 2, "service": 1 } },
"facetDefinitions": [
{ "key": "category", "label": "Category", "type": "multi" },
{ "key": "price", "label": "Price", "type": "range" }
]
}
facetDefinitions comes back with every answer so a client can build a filter panel from one
response: a multi facet is a list of values with counts, a range facet is a { min, max } pair
(empty when no document carries the value). It lists the standard set of the site plus the facets
its own product templates added.
A hit also carries item — the record it was built from — so a result block can render a card
without a second request.
The request is tolerant by design: an unknown key is ignored and a value it cannot read falls back to
the default, so a malformed query never answers 500 — it answers with the default it used.
Ordering by relevance is deterministic: hits with the same weight come back in a defined total order (newest first among equals on an external engine), so page N and page N + 1 of one query never repeat or skip a document.
GET /search/suggest?q=<prefix> answers up to ten { id, title, path } entries for a search box —
title matches first, then text matches — from the same site and the same index, with nothing extra
to configure.
Related
- Selecting content — the filter, sort and facet language the content index serves.
- Building a template — where the declarations in this page are written.
- Creating and editing records — the save that writes the index rows.
- Admin API reference — the settings, search and listing operations.