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

How to configure meilisearch index settings #21

Open
preetamslot opened this issue Nov 4, 2022 · 6 comments
Open

How to configure meilisearch index settings #21

preetamslot opened this issue Nov 4, 2022 · 6 comments

Comments

@preetamslot
Copy link

Hi,
how could I pass search configurations like searchableAttributes to an index?
https://docs.meilisearch.com/learn/core_concepts/indexes.html#index-settings

@donni106
Copy link

same question, found this issue. sadly no answers. did you find out a way @preetamslot?

@preetamslot
Copy link
Author

@donni106 In the end I created a function for this. something like:

const { MeiliSearch } = require("meilisearch");

const client = new MeiliSearch({
  host: "https://URL",
  apiKey: "KEY",
});

exports.main = async (args) => {

client.index("MY_COLLECTION").resetSettings();

const response = await client.index("MY_COLLECTION").updateSettings({
      rankingRules: [
        "words",
        "typo",
        "proximity",
        "attribute",
        "sort",
        "exactness",
        "priority:desc",
      ],
      distinctAttribute: "slug",
      searchableAttributes: [
        "title",
        "intro",
        ....
      ],
      filterableAttributes: [
        "id",
        "_geo",
        ...
      ],
      displayedAttributes: [
        'title',
        'overview',
        'genres',
        'release_date'
    ], 
      stopWords: ["the", "a", "an"],
      sortableAttributes: ["title"],
       synonyms: {
        'wolverine': ['xmen', 'logan'],
        'logan': ['wolverine']
    }, 
      typoTolerance: {
        'minWordSizeForTypos': {
            'oneTypo': 8,
            'twoTypos': 10
        },
        'disableOnAttributes': [
            'title'
        ]
    },
      pagination: {
        maxTotalHits: 500,
      },
       faceting: {
        maxValuesPerFacet: 200
    } 
    });
    
return { body: JSON.stringify(response) };

}

@donni106
Copy link

where do you place it and when do you call it?

@preetamslot
Copy link
Author

@donni106 I host this on Digital Ocean functions, but you could also host it on netlify, vercel, heroku or google cloud. It is just a node function. If you prefer other languages Meilisearch has the SDk for it:
https://docs.meilisearch.com/learn/what_is_meilisearch/sdks.html

@donni106
Copy link

donni106 commented Apr 4, 2023

Ah I understand, it is for running it whenever needed somewhere. True, this is nothing that an application needs on a regular base.

@preetamslot
Copy link
Author

@donni106 Yes! I only have to run the function when I have to reset the meilisearch or when I want to tweak the meilisearch settings.

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

No branches or pull requests

2 participants