diff --git a/apps/api/src/search/queries/course.ts b/apps/api/src/search/queries/course.ts index 000b80b93..7428e58c1 100644 --- a/apps/api/src/search/queries/course.ts +++ b/apps/api/src/search/queries/course.ts @@ -4,6 +4,8 @@ import { ICourseSearchFilter } from '@api/course/course.resolver' export function buildCourseQuery(filter: ICourseSearchFilter): Record { // create the base query from values that guarantee is not undefined const boolMust: Record[] = [] + const boolMustNot: Record[] = [] + const boolFilter: Record[] = [] if (filter.keyword) { boolMust.push({ @@ -56,50 +58,14 @@ export function buildCourseQuery(filter: ICourseSearchFilter): Record 0 && !(containsSU && containsLetter)) { + if (containsSU) { + boolFilter.push({ + wildcard: { creditHours: { value: '*(S/U)*' } }, }) - } else if (containsSU) { - boolMust.push({ - nested: { - path: 'rawData', - query: { - nested: { - path: 'rawData.creditHours', - query: { - bool: { - must: [ - { - wildcard: { - 'rawData.creditHours': '*S/U*', - }, - }, - ], - }, - }, - }, - }, - }, + } else if (containsLetter) { + boolMustNot.push({ + wildcard: { creditHours: { value: '*(S/U)*' } }, }) } } @@ -155,9 +121,7 @@ export function buildCourseQuery(filter: ICourseSearchFilter): Record 0) { - result['bool'] = { must: boolMust } - } + result['bool'] = { must: boolMust, must_not: boolMustNot, filter: boolFilter } return result }