Skip to content

Commit

Permalink
fix: opensearch add s/u
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Oct 4, 2023
1 parent 9c7703a commit 6a815c1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/api/src/course/course.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isTime } from '@api/util/functions'

import { Course, CourseDocument, DayOfWeek, GenEdType, Semester, StudyProgram } from '@cgr/schema'

import { CourseGroupInput, FilterInput, Period } from '../graphql'
import { CourseGroupInput, FilterInput, GradingType, Period } from '../graphql'
import { CourseService } from './course.service'

export interface ICourseSearchDocument {
Expand All @@ -29,6 +29,7 @@ export interface ICourseSearchDocument {
export interface ICourseSearchFilter {
keyword: string
genEdTypes?: GenEdType[]
gradingTypes?: GradingType[]
dayOfWeeks?: DayOfWeek[]
periodRange: Period
studyProgram: string
Expand Down Expand Up @@ -92,6 +93,7 @@ export class CourseResolver {
keyword: filter.keyword,
genEdTypes: filter.genEdTypes,
dayOfWeeks: filter.dayOfWeeks,
gradingTypes: filter.gradingTypes,
periodRange: filter.periodRange,
studyProgram: courseGroup.studyProgram,
semester: courseGroup.semester,
Expand Down
51 changes: 51 additions & 0 deletions apps/api/src/search/queries/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,57 @@ export function buildCourseQuery(filter: ICourseSearchFilter): Record<string, an
})
}

const containsSU = filter.gradingTypes?.includes('S_U')
const containsLetter = filter.gradingTypes?.includes('LETTER')

if (filter.gradingTypes && !(containsSU && containsLetter)) {
if (containsLetter) {
boolMust.push({
nested: {
path: 'rawData',
query: {
nested: {
path: 'rawData.creditHours',
query: {
bool: {
must_not: [
{
wildcard: {
'rawData.creditHours': '*S/U*',
},
},
],
},
},
},
},
},
})
} else if (containsSU) {
boolMust.push({
nested: {
path: 'rawData',
query: {
nested: {
path: 'rawData.creditHours',
query: {
bool: {
must: [
{
wildcard: {
'rawData.creditHours': '*S/U*',
},
},
],
},
},
},
},
},
})
}
}

if (sectionsQuery.length > 0) {
boolMust.push({
nested: {
Expand Down

0 comments on commit 6a815c1

Please sign in to comment.