Skip to content

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.

OptionDefaultWhat it does
apiKeyrequiredA Read only key. It rides in the URL, so a Write & Read key is refused.
urlhttps://search.typemo.comThe search host.
highlightFieldsnoneText fields to highlight when a request sets no attributesToHighlight.
onSearchIntentnoneCalled with the query and collection id when a visitor settles on a search.

It returns:

PropertyWhat it is
searchClientThe InstantSearch search client.
insightsThe value for InstantSearch’s insights option: clicks and conversions reach Typemo.
flushIntentRecords the pending search now. A result click or closing the search does it on its own.
disposeFor a search removed from a page that stays: records the pending search and drops listeners.

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.

  • 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 own sortBy overrides 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.

Parameters InstantSearch has no name for go through configure({ typemo: { … } }):

ParameterWhat it does
groupByGroups variants into one result by a field.
unavailableFacetValuesReturns the facet values the current filters rule out, marked as such.
langSearches the collection’s version in that language.
mode + documentIdFinds items similar to one document.
pinIds + pinsOnlyPins documents to the top, or returns only them.
autocompleteAdds 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.

These would change which documents match, and Typemo has no equivalent, so the adapter throws an error instead of returning unfiltered results:

ParameterUse instead
filters (the filter string)facetFilters, numericFilters
tagFiltersfacetFilters on a filter field
aroundLatLng, insideBoundingBox, insidePolygonNone: geo search isn’t supported

The standard widgets send facetFilters and numericFilters, so they work as they are.

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.

With insights passed, these reach Typemo’s analytics:

EventRecorded as
A click on a resultA click, tied to the search it came from
A conversionAn add-to-cart
A conversion with eventSubtype: 'purchase'A purchase, with objectData prices or a value, and currency
The query a visitor settled onA 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.