Updated fields search for postgres to support array item

Signed-off-by: rdeepc <12953177+rdeepc@users.noreply.github.com>
This commit is contained in:
rdeepc
2023-05-22 21:45:52 -04:00
parent 2d98053d52
commit 4b2a9b5509
2 changed files with 21 additions and 1 deletions
@@ -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',
},
]);
},
);
@@ -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,