Who this is for. The content modeller or theme developer deciding what a search can match and what a result can show. Afterwards you can map an area into the index, pick a field type the area will accept, and give every record type the same summary in a result list.
What a search field is
A search field is a name and a type, created under Search › Fields (the code calls it a master index field). It is defined once for the whole account and shared by every site on it. On its own it holds nothing. It fills when a layout area is pointed at it: from then on, every record whose layout has that area writes the area's value into fields.<name> in its search document.
Because the field is shared, areas from any number of layouts can fill it. A page layout's intro, a blog post layout's excerpt and a product description layout's shortDescription can all fill one summary field, and that is what lets one search return pages, posts and products with the same parts.
Field types, and the areas each accepts
A field's type has to suit the editor of the area's input type. An area pointed at a field of another type is refused when the layout is saved, with the message You need to use "text" field type for this area (or "double", "boolean", "date").
| Area editor | Field type | Matched by a query's words | What is stored |
|---|---|---|---|
text, textarea, richtext, email, code, math, select, multiselect | Text | Yes | The text with HTML tags removed; a select stores its option key, a multiselect each chosen key |
number | Double | No | A number |
switch | Bool | No | true or false |
date, datetime | Date | No | A date, and for a datetime its time |
Only Text fields are matched against a query and can be highlighted; Double, Bool and Date fields are for filtering and sorting. The admin also offers an Integer type, but no area editor maps to it, so no area can fill one. Image, file, record, records, component and component collection areas cannot be mapped at all. A record or records area needs no mapping to be useful: the ids it holds go into the document's relatedRecords on their own.
Mapping an area
- Create the field under Search › Fields, with a name and a type.
- Open the layout under Customization › Layouts, edit the area, switch on Index in search and choose the field under Index field. The list offers only the fields whose type suits the area's input type.
- Save the layout. Mapping an area, or changing the field it fills, queues a reindex of every site on the account, so existing records gain the field without being saved again (Reindexing).
- If the view lists its full text search fields, add the new field there with a weight, or its words are never matched. A view that lists no fields searches every field (Search views).
Two record types, one field
A site that shows a one-line summary under every result maps one plain-text area per layout into a Text field named summary, and the body text into a second Text field, content, which is used for matching and for snippets but never printed whole:
| Layout | Area (editor) | Search field |
|---|---|---|
| A page layout | intro (textarea) | summary |
| The blog post layout | excerpt (textarea) | summary |
| The product description layout | shortDescription (textarea) | summary |
| A text component, used in collections on all three | text (richtext) | content |
The result template then prints the same parts for every result, whatever its type: