Set Up a Search Page's Filter Panels
A dataset's Filter panels, in the Indx server's console, say which filters a search page shows,
in what order, under what names, and how each is drawn. A page reads them from the server, so the
filter column changes without a deploy. intrface's AutoFilters draws them by itself; a page with
panels of its own reads the same list over HTTP. Nothing has to be set: a field left alone gets what
Indx chooses for it, and a new field shows up at the end.
What Indx chooses by itself
Every field that is Filterable and Facetable is a candidate. Indx picks a panel from the
data: a list of values for text, a range for numbers, a switch for true and false, the category menu
for the levels set on the Categories tab. Fields that can't be a useful filter are left out, such as
a value nearly every record holds, and the names are made readable (release_year reads Release
year). A text field with very many values, a cast or a list of authors, is left off until you show
it; shown, its panel is a search field, and its values are fetched as the visitor types.
What the console sets
Each row of the tab is a field, in the order a page shows them: drag them, or use the arrows. Its switch shows or hides it. Click a row to open its panel, drawn as a page will draw it from your own data, and change:
- The name the visitor reads, and whether the panel starts folded.
- The panel: checkboxes, radio buttons, buttons in a grid, a range, or buckets.
- A range's layers, top to bottom: a histogram (off unless you turn it on), the slider, and the Min and Max inputs.
- A list: how many values it lists before Show more (0 lists none until the visitor types), a search field, the counts, the order (most records first, A to Z, or by value), and whether several ticks ask for records with every value or with any. By default a field that holds a list per record, such as genres, narrows with each tick, and a field with one value per record, such as a country, finds records with any of the ticked values.
Let Indx choose all sets every field back to Indx's choice. Review my filter panels asks Observr to propose an order, from how visitors use the panels, and clearer names; nothing changes until you accept it.
Panels that appear when they apply
A shop of many kinds of things has fields only some of its products have. Shoe size is noise on an empty search, and the first thing a visitor wants once the results are running shoes. Such a panel can wait until it applies:
- Always show, or
- when it applies: once a share of the results have a value in the field (30% by default), or once the field is far more common in the results than in the whole dataset (3 times by default, counted in at least 5% and 10 of the results; 0 turns it off).
Indx chooses when it applies by itself for a field few records have, and the tab marks it Conditional, with its rule on hover. A panel that applies arrives in one of two ways:
- Appear at the bottom (the default): it is added at the foot of the column, so nothing on screen moves.
- Show folded, unfold: it is there folded from the start, and unfolds in its place.
Once it has come it stays: when the results no longer have its field, it stays quietly where it is. While the visitor types, the column changes only once typing pauses (350 ms by default), so a word half typed doesn't flash panels past; ticking a filter changes it at once. It is worked out from the search's own counts, with no rules to write.
On the page: AutoFilters
import { SearchProvider, SearchInput, SearchResults } from '@indxsearch/intrface';
import { AutoFilters } from '@indxsearch/intrface/indx';
<SearchProvider url={url} team="my-team" dataset="products" preAuthenticatedToken={token}>
<SearchInput />
<AutoFilters />
<SearchResults>{product => <h3>{product.title}</h3>}</SearchResults>
</SearchProvider>AutoFilters reads the dataset's filter panels with the key the page searches with, and draws them
in Indx's look. A page can still overrule them: fields picks and orders the fields, labels,
kinds and exclude apply on top, and display sets one field's panel. settleMs sets the pause
before the column changes while typing.
Over HTTP
The same list, for a page with panels of its own:
GET /api/teams/{team}/datasets/{dataset}/filter-setupIt answers with the filters in order, each a field, its label, its kind (values, buttons,
range, buckets, toggle or hierarchy), and its display: among others when (always or
applies), arrive (appear or unfold), appliesFrom (a percentage) and jumpFrom (a factor).
A search key may read it. PUT the same path with { "fields": [ ... ] } to set them from code; an
empty list sets them back to Indx's choice.