Merge pull request #17922 from rdeepc/feat/add-postgress-array-field-search
This commit is contained in:
@@ -453,6 +453,18 @@ 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,
|
||||
{
|
||||
title: 'Consectetur adipiscing',
|
||||
text: 'Hello World',
|
||||
myField: ['that', 'not', 'where'],
|
||||
location: 'LOCATION-1',
|
||||
} as unknown as IndexableDocument,
|
||||
]);
|
||||
await store.completeInsert(tx, 'my-type');
|
||||
});
|
||||
@@ -488,6 +500,26 @@ 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',
|
||||
},
|
||||
{
|
||||
document: {
|
||||
location: 'LOCATION-1',
|
||||
text: 'Hello World',
|
||||
title: 'Consectetur adipiscing',
|
||||
myField: ['that', 'not', 'where'],
|
||||
},
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user