diff --git a/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.test.ts b/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.test.ts index 2f99a02521..0804f643ab 100644 --- a/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.test.ts +++ b/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.test.ts @@ -453,6 +453,12 @@ describe('DatabaseDocumentStore', () => { text: 'Around the world', location: 'LOCATION-1', }, + { + title: 'Sed ut perspiciatis', + text: 'Hello World', + myField: ['that', 'not'], + location: 'LOCATION-1', + } as unknown as IndexableDocument, ]); await store.completeInsert(tx, 'my-type'); }); @@ -488,6 +494,16 @@ describe('DatabaseDocumentStore', () => { rank: expect.any(Number), type: 'my-type', }, + { + document: { + location: 'LOCATION-1', + text: 'Hello World', + title: 'Sed ut perspiciatis', + myField: ['that', 'not'], + }, + rank: expect.any(Number), + type: 'my-type', + }, ]); }, ); diff --git a/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.ts b/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.ts index 023992a335..719cc1c755 100644 --- a/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.ts +++ b/plugins/search-backend-module-pg/src/database/DatabaseDocumentStore.ts @@ -171,9 +171,13 @@ export class DatabaseDocumentStore implements DatabaseStore { Object.keys(fields).forEach(key => { const value = fields[key]; const valueArray = Array.isArray(value) ? value : [value]; - const valueCompare = valueArray + const fieldValueCompare = valueArray .map(v => ({ [key]: v })) .map(v => JSON.stringify(v)); + const arrayValueCompare = valueArray + .map(v => ({ [key]: [v] })) + .map(v => JSON.stringify(v)); + const valueCompare = [...fieldValueCompare, ...arrayValueCompare]; query.whereRaw( `(${valueCompare.map(() => 'document @> ?').join(' OR ')})`, valueCompare,