InstantSearch adapter
@typemo-org/instantsearch-adapter gives InstantSearch a searchClient and an insights option
that run on Typemo. It works with InstantSearch.js, React InstantSearch, Vue InstantSearch and
@typemo-org/svelte-instantsearch, and needs no other search client. The walkthrough is in InstantSearch.
instantTypemo(options)
Section titled “instantTypemo(options)”| Option | Default | What it does |
|---|---|---|
apiKey | required | A Read only key. It rides in the URL, so a Write & Read key is refused. |
url | https://search.typemo.com | The search host. |
highlightFields | none | Text fields to highlight when a request sets no attributesToHighlight. |
onSearchIntent | none | Called with the query and collection id when a visitor settles on a search. |
It returns:
| Property | What it is |
|---|---|
searchClient | The InstantSearch search client. |
insights | The value for InstantSearch’s insights option: clicks and conversions reach Typemo. |
flushIntent | Records the pending search now. A result click or closing the search does it on its own. |
dispose | For a search removed from a page that stays: records the pending search and drops listeners. |
Index names and sorting
Section titled “Index names and sorting”An index name is a collection id. A sorted view is <collection>:<field>:asc|desc, so the items of a
SortBy widget look like your-collection-id and your-collection-id:price:asc. Any other shape
throws an error.
Requests
Section titled “Requests”- One action, one request. InstantSearch’s per-facet sub-requests are answered from the same search.
- Facet counts are always disjunctive, lists with
operator: 'and'included; their hits are right. Picking two or more values on a decimal field applies every selection to the counts too. - Facet values come in Typemo’s order (by count) through
renderingContent.facetOrdering. A widget’s ownsortByoverrides it. - A redirect from a custom result
arrives as
renderingContent.redirect.url, where Algolia sends one. Open it when the visitor submits the search. - Ranges (
RangeInput,RangeSlider) need the field set as a range filter on the collection. - Searchable lists match the typed text among the first 1,000 values of the field.
Typemo parameters
Section titled “Typemo parameters”Parameters InstantSearch has no name for go through configure({ typemo: { … } }):
| Parameter | What it does |
|---|---|
groupBy | Groups variants into one result by a field. |
unavailableFacetValues | Returns the facet values the current filters rule out, marked as such. |
lang | Searches the collection’s version in that language. |
mode + documentId | Finds items similar to one document. |
pinIds + pinsOnly | Pins documents to the top, or returns only them. |
autocomplete | Adds query completions. |
Pins and completions go with a query’s first page only, and completions only with a typed query.
What Typemo returns beyond InstantSearch’s shape is in results.typemo: autocomplete, fallback
(popular items for a search that found nothing) and facets with their statuses.
Refused parameters
Section titled “Refused parameters”These would change which documents match, and Typemo has no equivalent, so the adapter throws an error instead of returning unfiltered results:
| Parameter | Use instead |
|---|---|
filters (the filter string) | facetFilters, numericFilters |
tagFilters | facetFilters on a filter field |
aroundLatLng, insideBoundingBox, insidePolygon | None: geo search isn’t supported |
The standard widgets send facetFilters and numericFilters, so they work as they are.
Pages that aren’t a visitor’s search
Section titled “Pages that aren’t a visitor’s search”A start screen or another page your code fetches for itself shouldn’t count as a search. Call
searchClient.search(requests, { intent: false }): it records no search and doesn’t replace a newer
one.
Events
Section titled “Events”With insights passed, these reach Typemo’s analytics:
| Event | Recorded as |
|---|---|
| A click on a result | A click, tied to the search it came from |
| A conversion | An add-to-cart |
A conversion with eventSubtype: 'purchase' | A purchase, with objectData prices or a value, and currency |
| The query a visitor settled on | A search, the way the Typemo widget records it |
Views and filter events are not recorded. Recorded searches and clicks count in your analytics and popularity the same way the widget’s do.
Next: Search API for the parameters behind each request.