diff options
Diffstat (limited to 'packages/shared/search.ts')
| -rw-r--r-- | packages/shared/search.ts | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/packages/shared/search.ts b/packages/shared/search.ts index 8422d79e..7cd81061 100644 --- a/packages/shared/search.ts +++ b/packages/shared/search.ts @@ -1,7 +1,9 @@ -import { MeiliSearch, Index } from "meilisearch"; -import serverConfig from "./config"; +import type { Index } from "meilisearch"; +import { MeiliSearch } from "meilisearch"; import { z } from "zod"; +import serverConfig from "./config"; + export const zBookmarkIdxSchema = z.object({ id: z.string(), userId: z.string(), @@ -51,15 +53,29 @@ export async function getSearchIdxClient(): Promise<Index<ZBookmarkIdx> | null> 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); + 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); + 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; |
