Specified primaryKey to avoid problems with videos + filterable categories for libraryitem

This commit is contained in:
DrMint 2023-03-05 12:54:47 +01:00
parent 5a802b6347
commit 300752e684
3 changed files with 6 additions and 3 deletions

View File

@ -18,6 +18,7 @@ export interface MeiliLibraryItem extends LibraryItemAttributesFragment {
sortable_name: string; sortable_name: string;
sortable_price: number | undefined; sortable_price: number | undefined;
sortable_date: number | undefined; sortable_date: number | undefined;
filterable_categories: string[];
untangible_group_item: boolean; untangible_group_item: boolean;
} }

View File

@ -75,6 +75,9 @@ const transformLibraryItem: TransformFunction<MeiliIndices.LIBRARY_ITEM> = (data
attributes.price?.currency?.data?.attributes && isDefined(attributes.price.amount) attributes.price?.currency?.data?.attributes && isDefined(attributes.price.amount)
? attributes.price.amount * attributes.price.currency.data.attributes.rate_to_usd ? attributes.price.amount * attributes.price.currency.data.attributes.rate_to_usd
: undefined, : undefined,
filterable_categories: filterHasAttributes(attributes.categories?.data, [
"attributes.short",
] as const).map((category) => category.attributes.short),
untangible_group_item: isUntangibleGroupItem(attributes.metadata?.[0]), untangible_group_item: isUntangibleGroupItem(attributes.metadata?.[0]),
...attributes, ...attributes,
}; };

View File

@ -8,7 +8,6 @@ export const synchronizeStrapiAndMeili = async (): Promise<void> => {
const indexes = await meili.getIndexes(); const indexes = await meili.getIndexes();
await Promise.all(indexes.results.map(async (index) => index.delete())); await Promise.all(indexes.results.map(async (index) => index.delete()));
// [ LIBRARY ITEMS ] // [ LIBRARY ITEMS ]
const libraryItems = await sdk.getLibraryItems(); const libraryItems = await sdk.getLibraryItems();
@ -19,7 +18,7 @@ export const synchronizeStrapiAndMeili = async (): Promise<void> => {
), ),
["title", "subtitle", "descriptions"], ["title", "subtitle", "descriptions"],
["sortable_name", "sortable_date", "sortable_price"], ["sortable_name", "sortable_date", "sortable_price"],
["primary", "root_item", "id", "untangible_group_item"] ["primary", "root_item", "id", "untangible_group_item", "filterable_categories"]
); );
// [ CONTENT ] // [ CONTENT ]
@ -94,7 +93,7 @@ const processIndex = async <I extends MeiliDocumentsType["index"]>(
const meili = getMeili(); const meili = getMeili();
if (data && data.length > 0) { if (data && data.length > 0) {
await meili.createIndex(indexName); await meili.createIndex(indexName, { primaryKey: "id" });
const index = meili.index(indexName); const index = meili.index(indexName);
index.updateSettings({ index.updateSettings({
searchableAttributes: searchableAttributes as string[], searchableAttributes: searchableAttributes as string[],