Skip to content

Add per index meilisearchParams (for multi search) #1361

Open
@8byr0

Description

@8byr0

Description
Right now creating a client with custom params is done like this :

const client = instantMeiliSearch(
      "host",
      "key",
      {
        meiliSearchParams: {
          matchingStrategy: MatchingStrategies.ALL,
        },
      },
    ).searchClient;

Let's say I am on an ecommerce website searching in products and categories at the same time but want a different matching strategy. For example searching "i7 computer", I'd like suggested categories to include "Computers" but products to only include the ones with "i7" and "Computer" in its title or description.

To achieve such behavior I could then do :

const client = instantMeiliSearch(
      "host",
      "key",
      {
        meiliSearchParams: {
          products: { matchingStrategy: MatchingStrategies.ALL },
          categories: { matchingStrategy: MatchingStrategies.LAST },
        },
      },
    ).searchClient;

I can make a PR if you agree. We need to update the types and handle it here (and for every param):

addMatchingStrategy() {
const value = overrideParams?.matchingStrategy
if (value !== undefined) {
meiliSearchParams.matchingStrategy = value
}
},

like so :

    addMatchingStrategy() {
      const value = overrideParams?.matchingStrategy || overrideParams[indexUid].matchingStrategy;
      if (value !== undefined) {
        meiliSearchParams.matchingStrategy = value
      }
    },

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions