@vegan-friendly/strapi-plugin-elasticsearch 0.0.8

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.
Files changed (52) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +266 -0
  4. package/admin/src/components/Initializer/index.js +26 -0
  5. package/admin/src/components/PluginIcon/index.js +12 -0
  6. package/admin/src/components/SubNavigation/index.js +48 -0
  7. package/admin/src/index.js +63 -0
  8. package/admin/src/pages/App/index.js +29 -0
  9. package/admin/src/pages/ConfigureCollection/index.js +225 -0
  10. package/admin/src/pages/ConfigureCollectionList/index.js +266 -0
  11. package/admin/src/pages/Homepage/index.js +168 -0
  12. package/admin/src/pages/ViewIndexingRunLog/index.js +124 -0
  13. package/admin/src/pluginId.js +5 -0
  14. package/admin/src/translations/en.json +1 -0
  15. package/admin/src/translations/fr.json +1 -0
  16. package/admin/src/utils/apiUrls.js +14 -0
  17. package/admin/src/utils/axiosInstance.js +40 -0
  18. package/admin/src/utils/getTrad.js +5 -0
  19. package/package.json +40 -0
  20. package/server/bootstrap.js +142 -0
  21. package/server/config/index.js +6 -0
  22. package/server/content-types/index.js +9 -0
  23. package/server/content-types/indexing-logs.js +35 -0
  24. package/server/content-types/name-prefix.js +0 -0
  25. package/server/content-types/tasks.js +52 -0
  26. package/server/controllers/configure-indexing.js +66 -0
  27. package/server/controllers/index.js +15 -0
  28. package/server/controllers/log-indexing.js +11 -0
  29. package/server/controllers/perform-indexing.js +28 -0
  30. package/server/controllers/perform-search.js +31 -0
  31. package/server/controllers/setup-info.js +14 -0
  32. package/server/destroy.js +5 -0
  33. package/server/index.js +25 -0
  34. package/server/middlewares/index.js +3 -0
  35. package/server/policies/index.js +3 -0
  36. package/server/register.js +5 -0
  37. package/server/routes/configure-indexing.js +42 -0
  38. package/server/routes/index.js +13 -0
  39. package/server/routes/perform-indexing.js +24 -0
  40. package/server/routes/perform-search.js +14 -0
  41. package/server/routes/run-log.js +12 -0
  42. package/server/routes/setup-info.js +12 -0
  43. package/server/services/configure-indexing.js +184 -0
  44. package/server/services/es-interface.js +187 -0
  45. package/server/services/helper.js +305 -0
  46. package/server/services/index.js +19 -0
  47. package/server/services/log-indexing.js +26 -0
  48. package/server/services/perform-indexing.js +173 -0
  49. package/server/services/schedule-indexing.js +65 -0
  50. package/server/services/transform-content.js +22 -0
  51. package/strapi-admin.js +3 -0
  52. package/strapi-server.js +3 -0
@@ -0,0 +1,305 @@
1
+
2
+ ///START : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
3
+
4
+ const { isEmpty, merge } = require("lodash/fp");
5
+ const transformServiceProvider = require('./transform-content');
6
+
7
+ const getPluginStore = () => {
8
+ return strapi.store({
9
+ environment: '',
10
+ type: 'plugin',
11
+ name: 'elasticsearch',
12
+ });
13
+ }
14
+
15
+
16
+ const getModelPopulationAttributes = (model) => {
17
+ if (model.uid === "plugin::upload.file") {
18
+ const { related, ...attributes } = model.attributes;
19
+ return attributes;
20
+ }
21
+
22
+ return model.attributes;
23
+ };
24
+
25
+ const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
26
+ const skipCreatorFields = true;
27
+
28
+ if (maxDepth <= 1) {
29
+ return true;
30
+ }
31
+ if (modelUid === "admin::user" && skipCreatorFields) {
32
+ return undefined;
33
+ }
34
+
35
+ const populate = {};
36
+ const model = strapi.getModel(modelUid);
37
+ if (ignore && !ignore.includes(model.collectionName)) ignore.push(model.collectionName)
38
+ for (const [key, value] of Object.entries(
39
+ getModelPopulationAttributes(model)
40
+ )) {
41
+ if (ignore?.includes(key)) continue
42
+ if (value) {
43
+ if (value.type === "component") {
44
+ populate[key] = getFullPopulateObject(value.component, maxDepth - 1);
45
+ } else if (value.type === "dynamiczone") {
46
+ const dynamicPopulate = value.components.reduce((prev, cur) => {
47
+ const curPopulate = getFullPopulateObject(cur, maxDepth - 1);
48
+ return curPopulate === true ? prev : merge(prev, curPopulate);
49
+ }, {});
50
+ populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate;
51
+ } else if (value.type === "relation") {
52
+ const relationPopulate = getFullPopulateObject(
53
+ value.target,
54
+ (key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1,
55
+ ignore
56
+ );
57
+ if (relationPopulate) {
58
+ populate[key] = relationPopulate;
59
+ }
60
+ } else if (value.type === "media") {
61
+ populate[key] = true;
62
+ }
63
+ }
64
+ }
65
+ return isEmpty(populate) ? true : { populate };
66
+ };
67
+
68
+ ///END : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
69
+
70
+
71
+ /*
72
+ //Example config to cover extraction cases
73
+ collectionConfig[collectionName] = {
74
+ 'major' : {index: true},
75
+ 'sections' : { index: true, searchFieldName: 'information',
76
+ 'subfields' : [
77
+ { 'component' : 'try.paragraph',
78
+ 'field' : 'Text'},
79
+ { 'component' : 'try.paragraph',
80
+ 'field' : 'Heading'},
81
+ { 'component' : 'try.footer',
82
+ 'field' : 'footer_link',
83
+ 'subfields' :[ {
84
+ 'component' : 'try.link',
85
+ 'field' : 'display_text'
86
+ }]
87
+ }] },
88
+ 'seo_details' : {
89
+ index: true, searchFieldName: 'seo',
90
+ 'subfields' : [
91
+ {
92
+ 'component' : 'try.seo',
93
+ 'field' : 'meta_description'
94
+ }
95
+ ]
96
+ },
97
+ 'changelog' : {
98
+ index: true, searchFieldName: 'breakdown',
99
+ 'subfields' : [
100
+ {
101
+ 'component' : 'try.revision',
102
+ 'field' : 'summary'
103
+ }
104
+ ]
105
+ }
106
+ }
107
+ */
108
+ function extractSubfieldData({config, data }) {
109
+ let returnData = '';
110
+ if (Array.isArray(data))
111
+ {
112
+ const dynDataItems = data;
113
+ for (let r=0; r< dynDataItems.length; r++)
114
+ {
115
+ const extractItem = dynDataItems[r];
116
+ for (let s=0; s<config.length; s++)
117
+ {
118
+ const conf = config[s];
119
+ if (Object.keys(extractItem).includes('__component'))
120
+ {
121
+ if (conf.component === extractItem.__component &&
122
+ !Object.keys(conf).includes('subfields') &&
123
+ typeof extractItem[conf['field']] !== "undefined" &&
124
+ extractItem[conf['field']])
125
+ {
126
+ let val = extractItem[conf['field']]
127
+ if (Object.keys(conf).includes('transform')
128
+ && conf['transform'] === 'markdown')
129
+ val = transformServiceProvider.transform({content: val, from: 'markdown'});
130
+ returnData = returnData + '\n' + val;
131
+ }
132
+ else if (conf.component === extractItem.__component &&
133
+ Object.keys(conf).includes('subfields'))
134
+ {
135
+ returnData = returnData + '\n' + extractSubfieldData({
136
+ config: conf['subfields'], data: extractItem[conf['field']]});
137
+ }
138
+ }
139
+ else
140
+ {
141
+ if (!Object.keys(conf).includes('subfields') &&
142
+ typeof extractItem[conf['field']] !== "undefined" &&
143
+ extractItem[conf['field']])
144
+ {
145
+ let val = extractItem[conf['field']]
146
+ if (Object.keys(conf).includes('transform')
147
+ && conf['transform'] === 'markdown')
148
+ val = transformServiceProvider.transform({content: val, from: 'markdown'});
149
+ returnData = returnData + '\n' + val;
150
+ }
151
+ else if (Object.keys(conf).includes('subfields'))
152
+ {
153
+ returnData = returnData + '\n' + extractSubfieldData({
154
+ config: conf['subfields'], data: extractItem[conf['field']]});
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ else //for single component as a field
161
+ {
162
+ for (let s=0; s<config.length; s++)
163
+ {
164
+ const conf = config[s];
165
+ if (!Object.keys(conf).includes('subfields') &&
166
+ typeof data[conf['field']] !== "undefined" &&
167
+ data[conf['field']])
168
+ returnData = returnData + '\n' + data[conf['field']]
169
+ else if (Object.keys(conf).includes('subfields'))
170
+ {
171
+ returnData = returnData + '\n' + extractSubfieldData({
172
+ config: conf['subfields'], data: data[conf['field']]});
173
+ }
174
+ }
175
+ }
176
+ return returnData;
177
+ }
178
+
179
+ module.exports = ({ strapi }) => ({
180
+ async getElasticsearchInfo() {
181
+ const configureService = strapi.plugins['elasticsearch'].services.configureIndexing;
182
+ const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
183
+ const pluginConfig = await strapi.config.get('plugin.elasticsearch');
184
+
185
+ const connected = pluginConfig.searchConnector && pluginConfig.searchConnector.host
186
+ ? await esInterface.checkESConnection() : false;
187
+
188
+ return {
189
+ indexingCronSchedule : pluginConfig.indexingCronSchedule || "Not configured",
190
+ elasticHost : pluginConfig.searchConnector ?
191
+ pluginConfig.searchConnector.host || "Not configured" : "Not configured",
192
+ elasticUserName : pluginConfig.searchConnector ?
193
+ pluginConfig.searchConnector.username || "Not configured" : "Not configured",
194
+ elasticCertificate : pluginConfig.searchConnector ?
195
+ pluginConfig.searchConnector.certificate || "Not configured" : "Not configured",
196
+ elasticIndexAlias : pluginConfig.indexAliasName || "Not configured",
197
+ connected : connected,
198
+ initialized : configureService.isInitialized()
199
+ }
200
+ },
201
+ isCollectionDraftPublish({collectionName}) {
202
+ const model = strapi.getModel(collectionName);
203
+ return model.attributes.publishedAt ? true : false
204
+ },
205
+ getPopulateAttribute({collectionName}) {
206
+ //TODO : We currently have set populate to upto 4 levels, should
207
+ //this be configurable or a different default value?
208
+ return getFullPopulateObject(collectionName, 4, []);
209
+ },
210
+ getIndexItemId ({collectionName, itemId}) {
211
+ return collectionName+'::' + itemId;
212
+ },
213
+ async getCurrentIndexName () {
214
+ const pluginStore = getPluginStore();
215
+ const settings = await pluginStore.get({ key: 'configsettings' });
216
+ let indexName = 'strapi-plugin-elasticsearch-index_000001';
217
+ if (settings)
218
+ {
219
+ const objSettings = JSON.parse(settings);
220
+ if (Object.keys(objSettings).includes('indexConfig'))
221
+ {
222
+ const idxConfig = objSettings['indexConfig'];
223
+ indexName = idxConfig['name'];
224
+ }
225
+ }
226
+ return indexName;
227
+ },
228
+ async getIncrementedIndexName () {
229
+ const currentIndexName = await this.getCurrentIndexName();
230
+ const number = parseInt(currentIndexName.split('index_')[1]);
231
+ return 'strapi-plugin-elasticsearch-index_' + String(number+1).padStart(6,'0');
232
+ },
233
+ async storeCurrentIndexName (indexName) {
234
+ const pluginStore = getPluginStore();
235
+ const settings = await pluginStore.get({ key: 'configsettings' });
236
+ if (settings)
237
+ {
238
+ const objSettings = JSON.parse(settings);
239
+ objSettings['indexConfig'] = {'name' : indexName};
240
+ await pluginStore.set({ key: 'configsettings', value : JSON.stringify(objSettings)});
241
+ }
242
+ else
243
+ {
244
+ const newSettings = JSON.stringify({'indexConfig' : {'name' : indexName}})
245
+ await pluginStore.set({ key: 'configsettings', value : newSettings});
246
+ }
247
+ },
248
+ modifySubfieldsConfigForExtractor(collectionConfig) {
249
+ const collectionName = Object.keys(collectionConfig)[0];
250
+ const attributes = Object.keys(collectionConfig[collectionName]);
251
+ for (let r=0; r< attributes.length; r++)
252
+ {
253
+ const attr = attributes[r];
254
+ const attribFields = Object.keys(collectionConfig[collectionName][attr]);
255
+ if (attribFields.includes('subfields'))
256
+ {
257
+ const subfielddata = collectionConfig[collectionName][attr]['subfields'];
258
+ if (subfielddata.length > 0)
259
+ {
260
+ try {
261
+ const subfieldjson = JSON.parse(subfielddata)
262
+ if (Object.keys(subfieldjson).includes('subfields'))
263
+ collectionConfig[collectionName][attr]['subfields'] = subfieldjson['subfields']
264
+ }
265
+ catch(err)
266
+ {
267
+ continue;
268
+ }
269
+ }
270
+ }
271
+ }
272
+ return collectionConfig;
273
+ },
274
+ extractDataToIndex({collectionName, data, collectionConfig}) {
275
+ collectionConfig = this.modifySubfieldsConfigForExtractor(collectionConfig);
276
+ const fti = Object.keys(collectionConfig[collectionName]);
277
+ const document = {}
278
+ for (let k = 0; k < fti.length; k++)
279
+ {
280
+ const fieldConfig = collectionConfig[collectionName][fti[k]];
281
+ if (fieldConfig.index)
282
+ {
283
+ let val = null;
284
+ if (Object.keys(fieldConfig).includes('subfields'))
285
+ {
286
+ val = extractSubfieldData({config: fieldConfig['subfields'], data: data[fti[k]]})
287
+ val = val ? val.trim() : val
288
+ }
289
+ else
290
+ {
291
+ val = data[fti[k]];
292
+ if (Object.keys(fieldConfig).includes('transform') &&
293
+ fieldConfig['transform'] === 'markdown')
294
+ val = transformServiceProvider.transform({content: val, from: 'markdown'});
295
+ }
296
+
297
+ if (Object.keys(fieldConfig).includes('searchFieldName'))
298
+ document[fieldConfig['searchFieldName']] = val;
299
+ else
300
+ document[fti[k]] = val;
301
+ }
302
+ }
303
+ return document;
304
+ }
305
+ });
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const configureIndexing = require('./configure-indexing');
4
+ const scheduleIndexing = require('./schedule-indexing');
5
+ const esInterface = require('./es-interface');
6
+ const indexer = require('./perform-indexing');
7
+ const logIndexing = require('./log-indexing');
8
+ const helper = require('./helper');
9
+ const transformContent = require('./transform-content');
10
+
11
+ module.exports = {
12
+ configureIndexing,
13
+ scheduleIndexing,
14
+ esInterface,
15
+ indexer,
16
+ logIndexing,
17
+ helper,
18
+ transformContent
19
+ };
@@ -0,0 +1,26 @@
1
+ module.exports = ({ strapi }) => ({
2
+ async recordIndexingPass(message) {
3
+ const entry = await strapi.entityService.create('plugin::elasticsearch.indexing-log', {
4
+ data : {
5
+ status: 'pass',
6
+ details: message
7
+ }
8
+ });
9
+ },
10
+ async recordIndexingFail(message) {
11
+ const entry = await strapi.entityService.create('plugin::elasticsearch.indexing-log', {
12
+ data : {
13
+ status: 'fail',
14
+ details: String(message)
15
+ }
16
+ });
17
+ },
18
+ async fetchIndexingLogs(count = 50) {
19
+ const records = await strapi.entityService.findMany('plugin::elasticsearch.indexing-log', {
20
+ sort: { createdAt: 'DESC' },
21
+ start: 0,
22
+ limit: count
23
+ });
24
+ return records;
25
+ }
26
+ });
@@ -0,0 +1,173 @@
1
+
2
+ module.exports = ({ strapi }) => ({
3
+
4
+ async rebuildIndex() {
5
+ const helper = strapi.plugins['elasticsearch'].services.helper;
6
+ const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
7
+ const scheduleIndexingService = strapi.plugins['elasticsearch'].services.scheduleIndexing;
8
+ const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
9
+ const logIndexingService = strapi.plugins['elasticsearch'].services.logIndexing;
10
+
11
+ try
12
+ {
13
+ console.log('strapi-plugin-elasticsearch : Request to rebuild the index received.')
14
+ const oldIndexName = await helper.getCurrentIndexName();
15
+ console.log('strapi-plugin-elasticsearch : Recording the previous index name : ', oldIndexName);
16
+
17
+ //Step 1 : Create a new index
18
+ const newIndexName = await helper.getIncrementedIndexName();
19
+ await esInterface.createIndex(newIndexName);
20
+ console.log('strapi-plugin-elasticsearch : Created new index with name : ', newIndexName);
21
+
22
+
23
+ //Step 2 : Index all the stuff on this new index
24
+ console.log('strapi-plugin-elasticsearch : Starting to index all data into the new index.');
25
+ const item = await scheduleIndexingService.addFullSiteIndexingTask();
26
+
27
+ if (item.id)
28
+ {
29
+ const cols = await configureIndexingService.getCollectionsConfiguredForIndexing();
30
+ for (let r=0; r< cols.length; r++)
31
+ await this.indexCollection(cols[r], newIndexName);
32
+
33
+ await scheduleIndexingService.markIndexingTaskComplete(item.id);
34
+
35
+ console.log('strapi-plugin-elasticsearch : Indexing of data into the new index complete.');
36
+ //Step 4 : Move the alias to this new index
37
+ await esInterface.attachAliasToIndex(newIndexName);;
38
+ console.log('strapi-plugin-elasticsearch : Attaching the newly created index to the alias.')
39
+ //Step 3 : Update the search-indexing-name
40
+ await helper.storeCurrentIndexName(newIndexName);
41
+
42
+ console.log('strapi-plugin-elasticsearch : Deleting the previous index : ', oldIndexName);
43
+ //Step 5 : Delete the previous index
44
+ await esInterface.deleteIndex(oldIndexName)
45
+ await logIndexingService.recordIndexingPass('Request to immediately re-index site-wide content completed successfully.');
46
+
47
+ return true;
48
+ }
49
+ else
50
+ {
51
+ await logIndexingService.recordIndexingFail('An error was encountered while trying site-wide re-indexing of content.');
52
+ return false;
53
+ }
54
+ }
55
+ catch(err)
56
+ {
57
+ console.log('strapi-plugin-elasticsearch : searchController : An error was encountered while re-indexing.')
58
+ console.log(err);
59
+ await logIndexingService.recordIndexingFail(err);
60
+ }
61
+ },
62
+ async indexCollection(collectionName, indexName = null) {
63
+ const helper = strapi.plugins['elasticsearch'].services.helper;
64
+ const populateAttrib = helper.getPopulateAttribute({collectionName});
65
+ const isCollectionDraftPublish = helper.isCollectionDraftPublish({collectionName});
66
+ const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
67
+ const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
68
+ if (indexName === null)
69
+ indexName = await helper.getCurrentIndexName();
70
+ let entries = [];
71
+ if (isCollectionDraftPublish)
72
+ {
73
+ entries = await strapi.entityService.findMany(collectionName, {
74
+ sort: { createdAt: 'DESC' },
75
+ populate: populateAttrib['populate'],
76
+ filters: {
77
+ publishedAt: {
78
+ $notNull: true
79
+ }
80
+ }
81
+ });
82
+ }
83
+ else
84
+ {
85
+ entries = await strapi.entityService.findMany(collectionName, {
86
+ sort: { createdAt: 'DESC' },
87
+ populate: populateAttrib['populate'],
88
+ });
89
+ }
90
+ if (entries)
91
+ {
92
+ for (let s=0; s<entries.length; s++)
93
+ {
94
+ const item = entries[s];
95
+ const indexItemId = helper.getIndexItemId({collectionName: collectionName, itemId: item.id});
96
+ const collectionConfig = await configureIndexingService.getCollectionConfig({collectionName})
97
+ const dataToIndex = await helper.extractDataToIndex({
98
+ collectionName, data: item, collectionConfig
99
+ });
100
+ await esInterface.indexDataToSpecificIndex({itemId : indexItemId, itemData: dataToIndex}, indexName);
101
+ }
102
+ }
103
+ return true;
104
+ },
105
+ async indexPendingData() {
106
+ const scheduleIndexingService = strapi.plugins['elasticsearch'].services.scheduleIndexing;
107
+ const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
108
+ const logIndexingService = strapi.plugins['elasticsearch'].services.logIndexing;
109
+ const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
110
+ const helper = strapi.plugins['elasticsearch'].services.helper;
111
+ const recs = await scheduleIndexingService.getItemsPendingToBeIndexed();
112
+ const fullSiteIndexing = recs.filter(r => r.full_site_indexing === true).length > 0
113
+ if (fullSiteIndexing)
114
+ {
115
+ await this.rebuildIndex();
116
+ for (let r=0; r< recs.length; r++)
117
+ await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
118
+ }
119
+ else
120
+ {
121
+ try
122
+ {
123
+ for (let r=0; r< recs.length; r++)
124
+ {
125
+ const col = recs[r].collection_name;
126
+ if (configureIndexingService.isCollectionConfiguredToBeIndexed(col))
127
+ {
128
+ //Indexing the individual item
129
+ if (recs[r].item_id)
130
+ {
131
+ if (recs[r].indexing_type !== 'remove-from-index')
132
+ {
133
+ const populateAttrib = helper.getPopulateAttribute({collectionName: col});
134
+ const item = await strapi.entityService.findOne(col, recs[r].item_id, {
135
+ populate: populateAttrib['populate']
136
+ });
137
+ const indexItemId = helper.getIndexItemId({collectionName: col, itemId: item.id});
138
+ const collectionConfig = await configureIndexingService.getCollectionConfig({collectionName: col})
139
+ const dataToIndex = await helper.extractDataToIndex({
140
+ collectionName: col, data: item, collectionConfig
141
+ });
142
+ await esInterface.indexData({itemId : indexItemId, itemData: dataToIndex});
143
+ await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
144
+ }
145
+ else
146
+ {
147
+ const indexItemId = helper.getIndexItemId({collectionName: col, itemId: recs[r].item_id})
148
+ await esInterface.removeItemFromIndex({itemId : indexItemId});
149
+ await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
150
+ }
151
+ }
152
+ else //index the entire collection
153
+ {
154
+ //PENDING : Index an entire collection
155
+ await this.indexCollection(col);
156
+ await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
157
+ }
158
+ }
159
+ else
160
+ await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
161
+ }
162
+ await logIndexingService.recordIndexingPass('Indexing of ' + String(recs.length) + ' records complete.');
163
+ }
164
+ catch(err)
165
+ {
166
+ await logIndexingService.recordIndexingFail('Indexing of records failed - ' + ' ' + String(err));
167
+ console.log(err);
168
+ return false;
169
+ }
170
+ }
171
+ return true;
172
+ },
173
+ });
@@ -0,0 +1,65 @@
1
+
2
+
3
+ module.exports = ({ strapi }) => ({
4
+ async addFullSiteIndexingTask () {
5
+ const data = await strapi.entityService.create('plugin::elasticsearch.task', {
6
+ data : {
7
+ collection_name: '',
8
+ indexing_status: 'to-be-done',
9
+ full_site_indexing: true,
10
+ indexing_type: "add-to-index"
11
+ }
12
+ });
13
+ return data;
14
+ },
15
+ async addCollectionToIndex({collectionUid}) {
16
+ const data = await strapi.entityService.create('plugin::elasticsearch.task', {
17
+ data : {
18
+ collection_name: collectionUid,
19
+ indexing_status: 'to-be-done',
20
+ full_site_indexing: false,
21
+ indexing_type: "add-to-index"
22
+ }
23
+ });
24
+ return data;
25
+ },
26
+ async addItemToIndex({collectionUid, recordId}) {
27
+ const data = await strapi.entityService.create('plugin::elasticsearch.task', {
28
+ data : {
29
+ item_id: recordId,
30
+ collection_name: collectionUid,
31
+ indexing_status: 'to-be-done',
32
+ full_site_indexing: false,
33
+ indexing_type: "add-to-index"
34
+ }
35
+ });
36
+ return data;
37
+ },
38
+ async removeItemFromIndex({collectionUid, recordId}) {
39
+ const data = await strapi.entityService.create('plugin::elasticsearch.task', {
40
+ data : {
41
+ item_id: recordId,
42
+ collection_name: collectionUid,
43
+ indexing_status: 'to-be-done',
44
+ full_site_indexing: false,
45
+ indexing_type: "remove-from-index"
46
+ }
47
+ });
48
+ },
49
+ async getItemsPendingToBeIndexed(){
50
+ const entries = await strapi.entityService.findMany('plugin::elasticsearch.task', {
51
+ filters: { indexing_status : 'to-be-done'},
52
+ });
53
+ return entries;
54
+ },
55
+ async markIndexingTaskComplete (recId) {
56
+ const entries = await strapi.entityService.update('plugin::elasticsearch.task', recId, {
57
+ data : {
58
+ 'indexing_status' : 'done'
59
+ }
60
+ });
61
+ }
62
+
63
+
64
+
65
+ });
@@ -0,0 +1,22 @@
1
+ const { markdownToTxt } = require('markdown-to-txt');
2
+
3
+ function transformMarkdownToText(md) {
4
+ let text = md;
5
+ try {
6
+ text = markdownToTxt(md);
7
+ }
8
+ catch(err) {
9
+ console.error('strapi-plugin-elasticsearch : Error while transforming markdown to text.');
10
+ console.error(err);
11
+ }
12
+ return text;
13
+ }
14
+
15
+ module.exports = {
16
+ transform({content, from}) {
17
+ if (from === 'markdown')
18
+ return transformMarkdownToText(content);
19
+ else
20
+ return from;
21
+ },
22
+ };
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./admin/src').default;
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./server');