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

feature: handle per index meilisearch params #1364

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

8byr0
Copy link

@8byr0 8byr0 commented Jan 17, 2025

Pull Request

Related issue

Fixes #1361

What does this PR do?

  • Allow configuring meilisearchParams for each index individually (multi search)

From :

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

To :

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

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Copy link

changeset-bot bot commented Jan 17, 2025

⚠️ No Changeset found

Latest commit: 7c40e6e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@8byr0 8byr0 marked this pull request as ready for review January 17, 2025 16:29
@8byr0
Copy link
Author

8byr0 commented Jan 17, 2025

My initial proposal in #1364 was to be able to override directly like :

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

Unfortunately as far as I've seen it's not possible using typescript

This one works fine for accessing the values

export type OverridableMeiliSearchSearchParameters = BaseMeiliSearchSearchParameters & {
  [K in Exclude<string, keyof BaseMeiliSearchSearchParameters>]?: BaseMeiliSearchSearchParameters;
};
// No TS errors
const res = myobject[indexName].attributesToRetrieve;

// TS error
const meiliSearchParams: OverridableMeiliSearchSearchParameters = {
      attributesToHighlight: ['movies', 'genres'],
      highlightPreTag: '<em>',
      highlightPostTag: '</em>',
      matchingStrategy: MatchingStrategies.ALL,
    }

This one works fine for declaring values

export type OverridableMeiliSearchSearchParameters =
  | BaseMeiliSearchSearchParameters
  | (BaseMeiliSearchSearchParameters & {
      [K in Exclude<
        string,
        keyof BaseMeiliSearchSearchParameters
      >]?: BaseMeiliSearchSearchParameters
    })
// TS errors
const res = myobject[indexName].attributesToRetrieve;

// No TS errors
const meiliSearchParams: OverridableMeiliSearchSearchParameters = {
      attributesToHighlight: ['movies', 'genres'],
      highlightPreTag: '<em>',
      highlightPostTag: '</em>',
      matchingStrategy: MatchingStrategies.ALL,
    }

Open to discuss it if anyone has another approach in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add per index meilisearchParams (for multi search)
1 participant