-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(medusa-plugin-meilisearch): Update + improve Meilisearch plugin (#…
…3377) * feat(medusa-plugin-meilisearch): Upgrade meilisearch deps + migrate plugin to TS * fix version * Remove transaction base service from search service * Create .changeset/strange-mails-pump.md * Backward compatibility * Address PR feedback * Fix folder structure * Update readme * Move types * fix deps * Change version in changeset --------- Co-authored-by: adrien2p <[email protected]>
- Loading branch information
1 parent
4213326
commit 7e17e0d
Showing
21 changed files
with
377 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
"medusa-plugin-meilisearch": major | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(medusa-plugin-meilisearch): Update + improve Meilisearch plugin | ||
|
||
**What** | ||
- Bumps `meilisearch` dep to latest major | ||
- Migrates plugin to TypeScript | ||
- Changes the way indexes are configured in `medusa-config.js`: | ||
|
||
**Before** | ||
``` | ||
{ | ||
resolve: `medusa-plugin-meilisearch`, | ||
options: { | ||
config: { host: "...", apiKey: "..." }, | ||
settings: { | ||
products: { | ||
searchableAttributes: ["title"], | ||
displayedAttributes: ["title"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
``` | ||
|
||
**After** | ||
``` | ||
{ | ||
resolve: `medusa-plugin-meilisearch`, | ||
options: { | ||
config: { host: "...", apiKey: "..." }, | ||
settings: { | ||
products: { | ||
**indexSettings**: { | ||
searchableAttributes: ["title"], | ||
displayedAttributes: ["title"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
``` | ||
|
||
This is done to allow for additional configuration of indexes, that are not necessarily passed on query-time. | ||
|
||
We introduce two new settings: | ||
``` | ||
settings: { | ||
products: { | ||
indexSettings: { | ||
searchableAttributes: ["title"], | ||
displayedAttributes: ["title"],, | ||
}, | ||
primaryKey: "id" | ||
transformer: (document) => ({ id: "yo" }) | ||
}, | ||
}, | ||
``` | ||
|
||
Meilisearch changed their primary key inference in the major release. Now we must be explicit when multiple properties end with `id`. Read more in their [docs](https://docs.meilisearch.com/learn/core_concepts/primary_key.html#primary-field). | ||
|
||
The transformer allows developers to specify how their documents are stored in Meilisearch. It is configurable for each index. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,4 @@ | ||
/dist | ||
.env | ||
.DS_Store | ||
/uploads | ||
/node_modules | ||
yarn-error.log | ||
|
||
/dist | ||
|
||
/api | ||
/services | ||
/models | ||
/subscribers | ||
/loaders | ||
/utils | ||
dist | ||
node_modules | ||
.DS_store | ||
yarn.lock |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
module.exports = { | ||
testEnvironment: "node", | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "tsconfig.spec.json", | ||
isolatedModules: false, | ||
}, | ||
}, | ||
transform: { | ||
"^.+\\.[jt]s?$": "ts-jest", | ||
}, | ||
testEnvironment: `node`, | ||
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Logger, MedusaContainer } from "@medusajs/modules-sdk" | ||
import MeiliSearchService from "../services/meilisearch" | ||
import { MeilisearchPluginOptions } from "../types" | ||
|
||
export default async ( | ||
container: MedusaContainer, | ||
options: MeilisearchPluginOptions | ||
) => { | ||
const logger: Logger = container.resolve("logger") | ||
|
||
try { | ||
const meilisearchService: MeiliSearchService = | ||
container.resolve("meilisearchService") | ||
|
||
const { settings } = options | ||
|
||
await Promise.all( | ||
Object.entries(settings ?? []).map(([indexName, value]) => | ||
meilisearchService.updateSettings(indexName, value) | ||
) | ||
) | ||
} catch (err) { | ||
// ignore | ||
logger.warn(err) | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
packages/medusa-plugin-meilisearch/src/services/meilisearch.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.