Add search by recommendedBy group name

This commit is contained in:
Hongbo Wu
2022-12-05 14:53:29 +08:00
parent bf18c3d3c7
commit c49db571cd
3 changed files with 42 additions and 0 deletions

View File

@ -186,6 +186,19 @@ const appendIdsFilter = (body: SearchBody, ids: string[]): void => {
})
}
const appendRecommendedBy = (body: SearchBody, recommendedBy: string): void => {
body.query.bool.must.push({
nested: {
path: 'recommendedBy',
query: {
term: {
'recommendedBy.name': recommendedBy,
},
},
},
})
}
export const createPage = async (
page: Page,
ctx: PageContext
@ -441,6 +454,10 @@ export const searchPages = async (
appendIdsFilter(body, ids)
}
if (args.recommendedBy) {
appendRecommendedBy(body, args.recommendedBy)
}
if (!args.includePending) {
body.query.bool.must_not.push({
term: {

View File

@ -51,6 +51,16 @@ export interface SearchBody {
}
}
}
| {
nested: {
path: 'recommendedBy'
query: {
term: {
'recommendedBy.name': string
}
}
}
}
| {
match: {
[K: string]: string
@ -292,4 +302,5 @@ export interface PageSearchArgs {
includePending?: boolean | null
includeDeleted?: boolean
ids?: string[]
recommendedBy?: string
}

View File

@ -35,6 +35,7 @@ export interface SearchFilter {
termFilters: FieldFilter[]
matchFilters: FieldFilter[]
ids: string[]
recommendedBy?: string
}
export enum LabelFilterType {
@ -82,6 +83,14 @@ export interface FieldFilter {
value: string
}
const parseRecommendedBy = (str?: string): string | undefined => {
if (str === undefined) {
return undefined
}
return str.toLowerCase()
}
const parseIsFilter = (str: string | undefined): ReadFilter => {
switch (str?.toUpperCase()) {
case 'READ':
@ -300,6 +309,7 @@ export const parseSearchQuery = (query: string | undefined): SearchFilter => {
'content',
'updated',
'includes',
'recommendedBy',
],
tokenize: true,
})
@ -381,6 +391,10 @@ export const parseSearchQuery = (query: string | undefined): SearchFilter => {
ids && result.ids.push(...ids)
break
}
case 'recommendedBy': {
result.recommendedBy = parseRecommendedBy(keyword.value)
break
}
}
}
}