diff --git a/app/api/services/informationextraction/InformationExtraction.ts b/app/api/services/informationextraction/InformationExtraction.ts index a93bd29a0d..0aee74f5e2 100644 --- a/app/api/services/informationextraction/InformationExtraction.ts +++ b/app/api/services/informationextraction/InformationExtraction.ts @@ -186,9 +186,19 @@ class InformationExtraction { if (!entity) { return Promise.resolve(); } + + const [segmentation] = await SegmentationModel.get({ + xmlname: rawSuggestion.xml_file_name, + }); + + if (!segmentation) { + return Promise.resolve(); + } + const [currentSuggestion] = await IXSuggestionsModel.get({ entityId: entity.sharedId, propertyName: rawSuggestion.property_name, + fileId: segmentation.fileID, }); let status: 'ready' | 'failed' = 'ready'; @@ -207,9 +217,6 @@ class InformationExtraction { const suggestion: IXSuggestionType = { ...currentSuggestion, - entityId: entity.sharedId!, - language: entity.language!, - propertyName: rawSuggestion.property_name, suggestedValue, segment: rawSuggestion.segment_text, status, @@ -234,7 +241,7 @@ class InformationExtraction { ...existingSuggestions, entityId: entity.sharedId!, fileId: file._id, - language: entity.language!, + language: languages.get(file.language, 'ISO639_1') || 'other', propertyName, status: 'processing', date: new Date().getTime(), diff --git a/app/api/services/informationextraction/specs/InformationExtraction.spec.ts b/app/api/services/informationextraction/specs/InformationExtraction.spec.ts index 503c32debb..834c33243f 100644 --- a/app/api/services/informationextraction/specs/InformationExtraction.spec.ts +++ b/app/api/services/informationextraction/specs/InformationExtraction.spec.ts @@ -174,7 +174,7 @@ describe('InformationExtraction', () => { it('should create the suggestions placeholder with status processing', async () => { await informationExtraction.getSuggestions('property1'); const suggestions = await IXSuggestionsModel.get(); - expect(suggestions.length).toBe(4); + expect(suggestions.length).toBe(6); expect(suggestions.find(s => s.entityId === 'A1')).toEqual( expect.objectContaining({ entityId: 'A1', @@ -339,7 +339,7 @@ describe('InformationExtraction', () => { status: 'ready', propertyName: 'property1', }); - expect(suggestionsText.length).toBe(1); + expect(suggestionsText.length).toBe(2); const suggestionsMarkdown = await IXSuggestionsModel.get({ status: 'ready', diff --git a/app/api/services/informationextraction/specs/fixtures.ts b/app/api/services/informationextraction/specs/fixtures.ts index efa1120279..8d34e9f023 100644 --- a/app/api/services/informationextraction/specs/fixtures.ts +++ b/app/api/services/informationextraction/specs/fixtures.ts @@ -162,6 +162,7 @@ const fixtures: DBFixture = { ], ixsuggestions: [ { + fileId: factory.id('F1'), entityId: 'A1', language: 'en', propertyName: 'property1', @@ -171,6 +172,28 @@ const fixtures: DBFixture = { page: 1, date: 100, }, + { + fileId: factory.id('F3'), + entityId: 'A1', + language: 'en', + propertyName: 'property1', + suggestedValue: 'suggestion_text_2', + segment: 'segment_text_2', + status: 'ready', + page: 1, + date: 100, + }, + { + fileId: factory.id('F1'), + entityId: 'A1', + language: 'en', + propertyName: 'property4', + suggestedValue: 'suggestion_text_2', + segment: 'segment_text_2', + status: 'ready', + page: 1, + date: 100, + }, ], ixmodels: [ { propertyName: 'property1', creationDate: 200, status: 'ready' }, diff --git a/app/api/suggestions/IXSuggestionsModel.ts b/app/api/suggestions/IXSuggestionsModel.ts index b2ecdfaf8f..607dbd8406 100644 --- a/app/api/suggestions/IXSuggestionsModel.ts +++ b/app/api/suggestions/IXSuggestionsModel.ts @@ -12,7 +12,7 @@ const mongoSchema = new mongoose.Schema(props, { strict: false, }); -mongoSchema.index({ propertyName: 'text' }); +mongoSchema.index({ propertyName: 'text' }, { language_override: '_text' }); const IXSuggestionsModel = instanceModel('ixsuggestions', mongoSchema);