@porulle/adapter-meilisearch 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,aAAa,EAAE,KAAK,cAAc,EAA4E,MAAM,eAAe,CAAC;AAExK,UAAU,cAAc;IACtB,YAAY,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,GACA,OAAO,CAAC;QACT,IAAI,EAAE,KAAK,CAAC,cAAc,GAAG;YAAE,aAAa,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACzD,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KAC5D,CAAC,CAAC;IACH,0BAA0B,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,uBAAuB,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED,UAAU,eAAe;IACvB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;CACpC;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAoFD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa,CAyHpF"}
|
|
@@ -3,6 +3,9 @@ import { Err, Ok } from "@porulle/core";
|
|
|
3
3
|
const SAFE_ATTRIBUTE_NAME = /^[A-Za-z0-9_-]+$/;
|
|
4
4
|
function toFilter(params) {
|
|
5
5
|
const filters = [];
|
|
6
|
+
if (params.filters?.organizationId) {
|
|
7
|
+
filters.push(`organizationId = ${JSON.stringify(params.filters.organizationId)}`);
|
|
8
|
+
}
|
|
6
9
|
if (params.filters?.type) {
|
|
7
10
|
filters.push(`type = \"${params.filters.type}\"`);
|
|
8
11
|
}
|
|
@@ -60,7 +63,7 @@ function normalizeSearchResult(params, result) {
|
|
|
60
63
|
export function meilisearchAdapter(options) {
|
|
61
64
|
const client = options.client ?? new MeiliSearch({ host: options.host, ...(options.apiKey ? { apiKey: options.apiKey } : {}) });
|
|
62
65
|
const indexName = options.indexName ?? "catalog";
|
|
63
|
-
const filterable = options.filterableAttributes ?? ["type", "status", "categories", "brands"];
|
|
66
|
+
const filterable = options.filterableAttributes ?? ["organizationId", "type", "status", "categories", "brands"];
|
|
64
67
|
const attributeNames = new Set();
|
|
65
68
|
let configuredFilterable;
|
|
66
69
|
async function ensureFilterable(index, documents) {
|
|
@@ -146,8 +149,14 @@ export function meilisearchAdapter(options) {
|
|
|
146
149
|
async suggest(params) {
|
|
147
150
|
try {
|
|
148
151
|
const index = client.index(indexName);
|
|
152
|
+
const suggestFilters = [
|
|
153
|
+
...(params.organizationId
|
|
154
|
+
? [`organizationId = ${JSON.stringify(params.organizationId)}`]
|
|
155
|
+
: []),
|
|
156
|
+
...(params.type ? [`type = \"${params.type}\"`] : []),
|
|
157
|
+
];
|
|
149
158
|
const result = await index.search(params.prefix, {
|
|
150
|
-
...(
|
|
159
|
+
...(suggestFilters.length > 0 ? { filter: suggestFilters } : {}),
|
|
151
160
|
attributesToRetrieve: ["title"],
|
|
152
161
|
limit: params.limit ?? 10,
|
|
153
162
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@porulle/adapter-meilisearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"meilisearch": "^0.54.0",
|
|
15
|
-
"@porulle/core": "0.
|
|
15
|
+
"@porulle/core": "0.13.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "^24.5.2",
|
|
19
19
|
"eslint": "^9.39.1",
|
|
20
20
|
"typescript": "5.9.2",
|
|
21
21
|
"vitest": "^3.2.4",
|
|
22
|
-
"@porulle/
|
|
23
|
-
"@porulle/
|
|
22
|
+
"@porulle/typescript-config": "0.1.0",
|
|
23
|
+
"@porulle/eslint-config": "0.1.0"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,10 @@ const SAFE_ATTRIBUTE_NAME = /^[A-Za-z0-9_-]+$/;
|
|
|
39
39
|
function toFilter(params: SearchQueryParams): string[] {
|
|
40
40
|
const filters: string[] = [];
|
|
41
41
|
|
|
42
|
+
if (params.filters?.organizationId) {
|
|
43
|
+
filters.push(`organizationId = ${JSON.stringify(params.filters.organizationId)}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
if (params.filters?.type) {
|
|
43
47
|
filters.push(`type = \"${params.filters.type}\"`);
|
|
44
48
|
}
|
|
@@ -116,7 +120,7 @@ export function meilisearchAdapter(options: MeilisearchAdapterOptions): SearchAd
|
|
|
116
120
|
const client: MeiliClientLike =
|
|
117
121
|
options.client ?? new MeiliSearch({ host: options.host, ...(options.apiKey ? { apiKey: options.apiKey } : {}) });
|
|
118
122
|
const indexName = options.indexName ?? "catalog";
|
|
119
|
-
const filterable = options.filterableAttributes ?? ["type", "status", "categories", "brands"];
|
|
123
|
+
const filterable = options.filterableAttributes ?? ["organizationId", "type", "status", "categories", "brands"];
|
|
120
124
|
|
|
121
125
|
const attributeNames = new Set<string>();
|
|
122
126
|
let configuredFilterable: string[] | undefined;
|
|
@@ -204,8 +208,14 @@ export function meilisearchAdapter(options: MeilisearchAdapterOptions): SearchAd
|
|
|
204
208
|
async suggest(params: SearchSuggestParams): Promise<Result<string[]>> {
|
|
205
209
|
try {
|
|
206
210
|
const index = client.index(indexName);
|
|
211
|
+
const suggestFilters = [
|
|
212
|
+
...(params.organizationId
|
|
213
|
+
? [`organizationId = ${JSON.stringify(params.organizationId)}`]
|
|
214
|
+
: []),
|
|
215
|
+
...(params.type ? [`type = \"${params.type}\"`] : []),
|
|
216
|
+
];
|
|
207
217
|
const result = await index.search(params.prefix, {
|
|
208
|
-
...(
|
|
218
|
+
...(suggestFilters.length > 0 ? { filter: suggestFilters } : {}),
|
|
209
219
|
attributesToRetrieve: ["title"],
|
|
210
220
|
limit: params.limit ?? 10,
|
|
211
221
|
});
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,aAAa,EAAE,KAAK,cAAc,EAA4E,MAAM,eAAe,CAAC;AAExK,UAAU,cAAc;IACtB,YAAY,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,eAAe,CAAC,GA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