Skip to content

Commit

Permalink
test: add fallback for unsupported languages in elastic search indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao-vi committed Jan 7, 2025
1 parent f8bdc5d commit a63cb39
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/api/search/specs/entitiesIndex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { UserInContextMockFactory } from 'api/utils/testingUserInContext';
import db from 'api/utils/testing_db';
import { AccessLevels, PermissionType } from 'shared/types/permissionSchema';
import { UserRole } from 'shared/types/userSchema';
import { EntitySchema } from 'shared/types/entityType';
import { FileType } from 'shared/types/fileType';
import { elastic } from '../elastic';
import { reindexAll, updateMapping } from '../entitiesIndex';
import { search } from '../search';
Expand Down Expand Up @@ -159,4 +161,30 @@ describe('entitiesIndex', () => {
).toBeUndefined();
});
});

it('should fallback to "other" language if the language is not fully supported by elastic search', async () => {
const sharedId = db.id().toString();
const entities: EntitySchema[] = [{ sharedId, title: 'Entity 1', language: 'en' }];
const files: FileType[] = [
{
entity: sharedId,
originalname: 'file1',
filename: 'file1',
type: 'document',
mimetype: 'application/pdf',
language: 'ukr', // Ukrainian is not fully supported by elastic search
fullText: {},
totalPages: 0,
},
];

await db.setupFixturesAndContext({ entities, files });

await elasticTesting.reindex();

const [indexedFile] = await elasticTesting.getIndexedFullTextFromFiles();

expect(indexedFile.fullText_other).toBeDefined();
expect(indexedFile.fullText_undefined).not.toBeDefined();
});
});
17 changes: 17 additions & 0 deletions app/api/utils/elastic_testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ const elasticTesting = {
async getIndexedEntities(sort = 'title.sort') {
return (await elastic.search({ sort: [sort] })).body.hits.hits.map(i => i._source);
},

async getIndexedFullTextFromFiles() {
const result = await elastic.search({
body: {
query: {
has_parent: {
parent_type: 'entity',
query: {
match_all: {},
},
},
},
},
});

return result.body.hits.hits.map(i => i._source);
},
};

export { elasticTesting };

0 comments on commit a63cb39

Please sign in to comment.