Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create algolia-search-request and algolia-search-response packages #1160

Open
4 tasks
bidoubiwa opened this issue Jun 14, 2023 · 0 comments
Open
4 tasks

Create algolia-search-request and algolia-search-response packages #1160

bidoubiwa opened this issue Jun 14, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Jun 14, 2023

Context

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:

const instantMeilisearchClient = instantMeilisearch('host', 'apiKey');

const algoliaSearchParams = {
    "indexName": "games",
    "params": {
      "facets": [
        "genres"
      ],
      "hitsPerPage": 6,
      "page": 0,
      "query": "",
    }
}

const response = 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:

const searchParams = {
   indexUid: "games"
   facets: [
        "genres"
      ],
   q: "",
   // etc...
}

Solution

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'

const searchClient = algoliaSearchResponseClient('host', 'apiKey')

const searchParams = {
   indexUid: "games"
   facets: [
        "genres"
      ],
   q: "",
   // etc...
}

const algoliaSearchResponse = await searchClient.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 sources
import { algoliaSearchRequestClient } from '@meilisearch/algolia-search-request'

const searchClient = algoliaSearchRequestClient('host', 'apiKey', { userAgent: ['autocomplete (vx.x.x)'] })

const algoliasearchParams = {
   indexName: "games",
   params: { query: "test" }
}

const meilisearchResponse = await searchClient.search([algoliaSearchParams])

In the above example, the user agent sends to Meilisearch the engine are now

meilisearch js (vx.x.x); autocomplete-client (v.x.x.x)

instead of

meilisearch js (vx.x.x); instant-meilisearch (vx.x.x) autocomplete-client (v.x.x.x)

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 and algoliaSearchResponseClient ?

Todo

@bidoubiwa bidoubiwa added the enhancement New feature or request label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant