You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
instant-meilisearch is an adapter between instantsearch and algoliasearch.js.
The way it works is that instantsearch provides search requests compatible with the search method of algoliasearch.js. It then expects a search response in the format that is returned by the search method of algoliasearch.js.
The role of instant-meilisearch is to transform the Algolia search requests into meilisearch search requests and then transform the meilisearch search response into an algoliasearch response format.
Problem
Since instant-meilisearch is the adapter of algolia, instant-meilisearch is used by autocomplete-client for the same purpose as described above: adapting the search request and response. This constitute the first problem, as instant-meilisearch also provides the possibility to send configurations specifically related to instant-meilisearch which are not relevant to autocomplete-client and autocomplete-client user agent always contains instant-meilisearch in its agents.
The second issue lies when the user wants to use instantsearch in a SSR environment. Typically, a user might want to create a first back-end search and build the website with the returned hits. By doing so, the first hits are referenced on the different search engines (SEO) and the initial load of the hits is way faster. This is a common implementation on e-commerce websites.
Currently, this is only possible if the user creates an algolia search request. Which means, using the search request parameters of algolia.
For example:
The user wants to build its website with an initial search. He needs to do the following:
constinstantMeilisearchClient=instantMeilisearch('host','apiKey');constalgoliaSearchParams={"indexName": "games","params": {"facets": ["genres"],"hitsPerPage": 6,"page": 0,"query": "",}}constresponse=instantMeilisearchClient.search([algoliaSearchParams]);// use response as initial search in the instantSearch instance
As you can see, the search request was made using the algoliasearch format and not the meilisearch format. It would have been more intuitive if the user could make a request with Meilisearch search parameters:
To be able to provide this intuitive SSR experience, we need to extract two parts of instant-meilisearch. The algolia-search-request adapter and the algolia-search-response adapter.
By doing so, the user can now create a SSR initial search with Meilisearch search parameters:
import{algoliaSearchResponseClient}from'@meilisearch/algolia-search-response'constsearchClient=algoliaSearchResponseClient('host','apiKey')constsearchParams={indexUid: "games"facets: ["genres"],q: "",// etc...}constalgoliaSearchResponse=awaitsearchClient.search([searchParams]);// search response in an algoliasearch.js format// use response as initial search in the instantSearch instance
By using the searchRequest adapter, autocomplete can also remove instant-meilisearch from its user-agents.
// in autocomplete sourcesimport{algoliaSearchRequestClient}from'@meilisearch/algolia-search-request'constsearchClient=algoliaSearchRequestClient('host','apiKey',{userAgent: ['autocomplete (vx.x.x)']})constalgoliasearchParams={indexName: "games",params: {query: "test"}}constmeilisearchResponse=awaitsearchClient.search([algoliaSearchParams])
In the above example, the user agent sends to Meilisearch the engine are now
Context
instant-meilisearch
is an adapter betweeninstantsearch
andalgoliasearch.js
.The way it works is that
instantsearch
providessearch requests compatible
with the search method of algoliasearch.js. It then expects a search response in the format that is returned by the search method of algoliasearch.js.The role of
instant-meilisearch
is to transform the Algolia search requests into meilisearch search requests and then transform the meilisearch search response into an algoliasearch response format.Problem
Since
instant-meilisearch
is the adapter of algolia,instant-meilisearch
is used byautocomplete-client
for the same purpose as described above: adapting the search request and response. This constitute the first problem, as instant-meilisearch also provides the possibility to send configurations specifically related to instant-meilisearch which are not relevant to autocomplete-client and autocomplete-client user agent always containsinstant-meilisearch
in its agents.The second issue lies when the user wants to use
instantsearch
in a SSR environment. Typically, a user might want to create a first back-end search and build the website with the returned hits. By doing so, the first hits are referenced on the different search engines (SEO) and the initial load of the hits is way faster. This is a common implementation on e-commerce websites.Currently, this is only possible if the user creates an algolia search request. Which means, using the search request parameters of algolia.
For example:
The user wants to build its website with an initial search. He needs to do the following:
As you can see, the search request was made using the
algoliasearch
format and not themeilisearch
format. It would have been more intuitive if the user could make a request with Meilisearch search parameters:Solution
To be able to provide this intuitive SSR experience, we need to extract two parts of
instant-meilisearch
. Thealgolia-search-request
adapter and thealgolia-search-response
adapter.By doing so, the user can now create a SSR initial search with Meilisearch search parameters:
By using the
searchRequest
adapter, autocomplete can also removeinstant-meilisearch
from its user-agents.In the above example, the user agent sends to Meilisearch the engine are now
instead of
Design choices.
How should we name both packages?
@meilisearch/algolia-search-request-adapter
and@meilisearch/algolia-search-response-adapter
?How should we name the methods that are served by these packages?
algoliaSearchRequestClient
andalgoliaSearchResponseClient
?Todo
@meilisearch/algolia-search-request-adapter
package@meilisearch/algolia-search-response-adapter
package.The text was updated successfully, but these errors were encountered: