diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts index 3ed002567e..e106cd6f06 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts @@ -271,6 +271,21 @@ describe('PgSearchEngine', () => { limit: 26, }); }); + + it('should throws missing index error', async () => { + database.transaction.mockImplementation(fn => fn(tx)); + database.query.mockResolvedValue([]); + await expect( + async () => + await searchEngine.query({ + term: 'testTerm', + types: ['unknown'], + filters: {}, + }), + ).rejects.toThrow( + 'Missing index for unknown. This means there are no documents to search through', + ); + }); }); }); diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts index d8128f8568..065f25878c 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts @@ -93,7 +93,7 @@ export class PgSearchEngine implements SearchEngine { this.databaseStore.query(tx, pgQuery), ); - if (!rows.length) { + if (pgQuery?.types && !rows.length) { throw new MissingIndexError( `Missing index for ${pgQuery.types}. This means there are no documents to search through.`, );