strapi-plugin-meilisearch-plus 0.2.1 → 0.2.3
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.
- package/dist/server/index.js +41 -32
- package/dist/server/index.mjs +41 -32
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -863,46 +863,56 @@ const meilisearch = ({ strapi }) => ({
|
|
|
863
863
|
}
|
|
864
864
|
let indexWasJustCreated = false;
|
|
865
865
|
try {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
866
|
+
try {
|
|
867
|
+
strapi.log.info(`[meilisearch-plus] Creating index ${finalIndexName}`);
|
|
868
|
+
await client.createIndex(finalIndexName);
|
|
869
|
+
indexWasJustCreated = true;
|
|
870
|
+
await client.index(finalIndexName).updateSettings({
|
|
871
|
+
primaryKey: "id"
|
|
872
|
+
});
|
|
869
873
|
strapi.log.info(
|
|
870
|
-
`[meilisearch-plus] Index ${finalIndexName}
|
|
874
|
+
`[meilisearch-plus] ✓ Index ${finalIndexName} created with primaryKey: 'id'`
|
|
871
875
|
);
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const indexSettings2 = await client.index(finalIndexName).getSettings();
|
|
877
|
-
const currentPrimaryKey = indexSettings2.primaryKey;
|
|
878
|
-
if (currentPrimaryKey !== "id") {
|
|
879
|
-
strapi.log.warn(
|
|
880
|
-
`[meilisearch-plus] Index ${finalIndexName} has primaryKey: '${currentPrimaryKey}' but expected 'id'. Updating...`
|
|
876
|
+
} catch (createError) {
|
|
877
|
+
if (createError.code === "index_already_exists" || createError.message?.includes("already exists")) {
|
|
878
|
+
strapi.log.info(
|
|
879
|
+
`[meilisearch-plus] Index ${finalIndexName} already exists, checking primary key...`
|
|
881
880
|
);
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
});
|
|
886
|
-
strapi.log.info(
|
|
887
|
-
`[meilisearch-plus] ✓ Updated index ${finalIndexName} primaryKey to 'id'`
|
|
888
|
-
);
|
|
889
|
-
} catch (updateError) {
|
|
890
|
-
strapi.log.error(
|
|
891
|
-
`[meilisearch-plus] Could not update primaryKey for ${finalIndexName}:`,
|
|
892
|
-
updateError.message
|
|
893
|
-
);
|
|
881
|
+
const indexSettings2 = await client.index(finalIndexName).getSettings();
|
|
882
|
+
const currentPrimaryKey = indexSettings2.primaryKey;
|
|
883
|
+
if (currentPrimaryKey !== "id") {
|
|
894
884
|
strapi.log.warn(
|
|
895
|
-
`[meilisearch-plus] Index ${finalIndexName}
|
|
885
|
+
`[meilisearch-plus] Index ${finalIndexName} has primaryKey: '${currentPrimaryKey}' but expected 'id'. Deleting and recreating...`
|
|
886
|
+
);
|
|
887
|
+
try {
|
|
888
|
+
await client.deleteIndex(finalIndexName);
|
|
889
|
+
strapi.log.info(`[meilisearch-plus] ✓ Deleted index ${finalIndexName}`);
|
|
890
|
+
await client.createIndex(finalIndexName);
|
|
891
|
+
await client.index(finalIndexName).updateSettings({
|
|
892
|
+
primaryKey: "id"
|
|
893
|
+
});
|
|
894
|
+
indexWasJustCreated = true;
|
|
895
|
+
strapi.log.info(
|
|
896
|
+
`[meilisearch-plus] ✓ Recreated index ${finalIndexName} with primaryKey: 'id'`
|
|
897
|
+
);
|
|
898
|
+
} catch (recreateError) {
|
|
899
|
+
strapi.log.error(
|
|
900
|
+
`[meilisearch-plus] Could not recreate index ${finalIndexName}:`,
|
|
901
|
+
recreateError.message
|
|
902
|
+
);
|
|
903
|
+
throw recreateError;
|
|
904
|
+
}
|
|
905
|
+
} else {
|
|
906
|
+
strapi.log.info(
|
|
907
|
+
`[meilisearch-plus] Index ${finalIndexName} exists with correct primaryKey: 'id'`
|
|
896
908
|
);
|
|
897
909
|
}
|
|
898
910
|
} else {
|
|
899
|
-
|
|
900
|
-
`[meilisearch-plus] Index ${finalIndexName} exists with correct primaryKey: 'id'`
|
|
901
|
-
);
|
|
911
|
+
throw createError;
|
|
902
912
|
}
|
|
903
913
|
}
|
|
904
914
|
} catch (error) {
|
|
905
|
-
strapi.log.error(`[meilisearch-plus] Error
|
|
915
|
+
strapi.log.error(`[meilisearch-plus] Error ensuring index ${finalIndexName}:`, error);
|
|
906
916
|
throw error;
|
|
907
917
|
}
|
|
908
918
|
const index2 = client.index(finalIndexName);
|
|
@@ -923,8 +933,7 @@ const meilisearch = ({ strapi }) => ({
|
|
|
923
933
|
let taskUids = [];
|
|
924
934
|
for (let i = 0; i < sanitized.length; i += this.BATCH_SIZE) {
|
|
925
935
|
const batch = sanitized.slice(i, i + this.BATCH_SIZE);
|
|
926
|
-
const
|
|
927
|
-
const response = await index2.addDocuments(batch, addOptions);
|
|
936
|
+
const response = await index2.addDocuments(batch);
|
|
928
937
|
strapi.log.info(
|
|
929
938
|
`[meilisearch-plus] Added batch of ${batch.length} documents for ${contentType} (Task uid: ${response.taskUid})`
|
|
930
939
|
);
|
package/dist/server/index.mjs
CHANGED
|
@@ -862,46 +862,56 @@ const meilisearch = ({ strapi }) => ({
|
|
|
862
862
|
}
|
|
863
863
|
let indexWasJustCreated = false;
|
|
864
864
|
try {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
865
|
+
try {
|
|
866
|
+
strapi.log.info(`[meilisearch-plus] Creating index ${finalIndexName}`);
|
|
867
|
+
await client.createIndex(finalIndexName);
|
|
868
|
+
indexWasJustCreated = true;
|
|
869
|
+
await client.index(finalIndexName).updateSettings({
|
|
870
|
+
primaryKey: "id"
|
|
871
|
+
});
|
|
868
872
|
strapi.log.info(
|
|
869
|
-
`[meilisearch-plus] Index ${finalIndexName}
|
|
873
|
+
`[meilisearch-plus] ✓ Index ${finalIndexName} created with primaryKey: 'id'`
|
|
870
874
|
);
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
const indexSettings2 = await client.index(finalIndexName).getSettings();
|
|
876
|
-
const currentPrimaryKey = indexSettings2.primaryKey;
|
|
877
|
-
if (currentPrimaryKey !== "id") {
|
|
878
|
-
strapi.log.warn(
|
|
879
|
-
`[meilisearch-plus] Index ${finalIndexName} has primaryKey: '${currentPrimaryKey}' but expected 'id'. Updating...`
|
|
875
|
+
} catch (createError) {
|
|
876
|
+
if (createError.code === "index_already_exists" || createError.message?.includes("already exists")) {
|
|
877
|
+
strapi.log.info(
|
|
878
|
+
`[meilisearch-plus] Index ${finalIndexName} already exists, checking primary key...`
|
|
880
879
|
);
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
});
|
|
885
|
-
strapi.log.info(
|
|
886
|
-
`[meilisearch-plus] ✓ Updated index ${finalIndexName} primaryKey to 'id'`
|
|
887
|
-
);
|
|
888
|
-
} catch (updateError) {
|
|
889
|
-
strapi.log.error(
|
|
890
|
-
`[meilisearch-plus] Could not update primaryKey for ${finalIndexName}:`,
|
|
891
|
-
updateError.message
|
|
892
|
-
);
|
|
880
|
+
const indexSettings2 = await client.index(finalIndexName).getSettings();
|
|
881
|
+
const currentPrimaryKey = indexSettings2.primaryKey;
|
|
882
|
+
if (currentPrimaryKey !== "id") {
|
|
893
883
|
strapi.log.warn(
|
|
894
|
-
`[meilisearch-plus] Index ${finalIndexName}
|
|
884
|
+
`[meilisearch-plus] Index ${finalIndexName} has primaryKey: '${currentPrimaryKey}' but expected 'id'. Deleting and recreating...`
|
|
885
|
+
);
|
|
886
|
+
try {
|
|
887
|
+
await client.deleteIndex(finalIndexName);
|
|
888
|
+
strapi.log.info(`[meilisearch-plus] ✓ Deleted index ${finalIndexName}`);
|
|
889
|
+
await client.createIndex(finalIndexName);
|
|
890
|
+
await client.index(finalIndexName).updateSettings({
|
|
891
|
+
primaryKey: "id"
|
|
892
|
+
});
|
|
893
|
+
indexWasJustCreated = true;
|
|
894
|
+
strapi.log.info(
|
|
895
|
+
`[meilisearch-plus] ✓ Recreated index ${finalIndexName} with primaryKey: 'id'`
|
|
896
|
+
);
|
|
897
|
+
} catch (recreateError) {
|
|
898
|
+
strapi.log.error(
|
|
899
|
+
`[meilisearch-plus] Could not recreate index ${finalIndexName}:`,
|
|
900
|
+
recreateError.message
|
|
901
|
+
);
|
|
902
|
+
throw recreateError;
|
|
903
|
+
}
|
|
904
|
+
} else {
|
|
905
|
+
strapi.log.info(
|
|
906
|
+
`[meilisearch-plus] Index ${finalIndexName} exists with correct primaryKey: 'id'`
|
|
895
907
|
);
|
|
896
908
|
}
|
|
897
909
|
} else {
|
|
898
|
-
|
|
899
|
-
`[meilisearch-plus] Index ${finalIndexName} exists with correct primaryKey: 'id'`
|
|
900
|
-
);
|
|
910
|
+
throw createError;
|
|
901
911
|
}
|
|
902
912
|
}
|
|
903
913
|
} catch (error) {
|
|
904
|
-
strapi.log.error(`[meilisearch-plus] Error
|
|
914
|
+
strapi.log.error(`[meilisearch-plus] Error ensuring index ${finalIndexName}:`, error);
|
|
905
915
|
throw error;
|
|
906
916
|
}
|
|
907
917
|
const index2 = client.index(finalIndexName);
|
|
@@ -922,8 +932,7 @@ const meilisearch = ({ strapi }) => ({
|
|
|
922
932
|
let taskUids = [];
|
|
923
933
|
for (let i = 0; i < sanitized.length; i += this.BATCH_SIZE) {
|
|
924
934
|
const batch = sanitized.slice(i, i + this.BATCH_SIZE);
|
|
925
|
-
const
|
|
926
|
-
const response = await index2.addDocuments(batch, addOptions);
|
|
935
|
+
const response = await index2.addDocuments(batch);
|
|
927
936
|
strapi.log.info(
|
|
928
937
|
`[meilisearch-plus] Added batch of ${batch.length} documents for ${contentType} (Task uid: ${response.taskUid})`
|
|
929
938
|
);
|
package/package.json
CHANGED