Allow search recommendations with wildcard

This commit is contained in:
Hongbo Wu 2022-12-12 22:09:25 +08:00
parent 1338b1fc10
commit 3e79b86179
2 changed files with 18 additions and 6 deletions

View file

@ -187,14 +187,23 @@ const appendIdsFilter = (body: SearchBody, ids: string[]): void => {
}
const appendRecommendedBy = (body: SearchBody, recommendedBy: string): void => {
const query =
recommendedBy === '*'
? {
exists: {
field: 'recommendations',
},
}
: {
term: {
'recommendations.name': recommendedBy,
},
}
body.query.bool.must.push({
nested: {
path: 'recommendations',
query: {
term: {
'recommendations.name': recommendedBy,
},
},
query,
},
})
}

View file

@ -55,7 +55,10 @@ export interface SearchBody {
nested: {
path: 'recommendations'
query: {
term: {
exists?: {
field: string
}
term?: {
'recommendations.name': string
}
}