diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-30 15:44:17 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-30 15:44:17 +0000 |
| commit | 853ed13450b3a0d92cba144cc0dfd0696e7c810c (patch) | |
| tree | 7e654b5d32e7c4b8e69091c48dcab89eb7b50bad /packages/shared/search.ts | |
| parent | e99dee0b4f7220568c8ffa2755147bc45d35b32b (diff) | |
| download | karakeep-853ed13450b3a0d92cba144cc0dfd0696e7c810c.tar.zst | |
fix: Sort search results by relevance
Diffstat (limited to 'packages/shared/search.ts')
| -rw-r--r-- | packages/shared/search.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/shared/search.ts b/packages/shared/search.ts index 89a41329..8422d79e 100644 --- a/packages/shared/search.ts +++ b/packages/shared/search.ts @@ -9,6 +9,7 @@ export const zBookmarkIdxSchema = z.object({ title: z.string().nullish(), description: z.string().nullish(), content: z.string().nullish(), + createdAt: z.string().nullish(), note: z.string().nullish(), tags: z.array(z.string()).default([]), }); @@ -44,8 +45,23 @@ export async function getSearchIdxClient(): Promise<Index<ZBookmarkIdx> | null> }); await searchClient.waitForTask(idx.taskUid); idxFound = await searchClient.getIndex<ZBookmarkIdx>(BOOKMARKS_IDX_NAME); - const taskId = await idxFound.updateFilterableAttributes(["id", "userId"]); + } + + const desiredFilterableAttributes = ["id", "userId"].sort(); + const desiredSortableAttributes = ["createdAt"].sort(); + + const settings = await idxFound.getSettings(); + if (JSON.stringify(settings.filterableAttributes?.sort()) != JSON.stringify(desiredFilterableAttributes)) { + console.log(`[meilisearch] Updating desired filterable attributes to ${desiredFilterableAttributes} from ${settings.filterableAttributes}`); + const taskId = await idxFound.updateFilterableAttributes(desiredFilterableAttributes); + await searchClient.waitForTask(taskId.taskUid); + } + + if (JSON.stringify(settings.sortableAttributes?.sort()) != JSON.stringify(desiredSortableAttributes)) { + console.log(`[meilisearch] Updating desired sortable attributes to ${desiredSortableAttributes} from ${settings.sortableAttributes}`); + const taskId = await idxFound.updateSortableAttributes(desiredSortableAttributes); await searchClient.waitForTask(taskId.taskUid); } + idxClient = idxFound; return idxFound; } |
