From 4df07033a9047f8bf5b9dae54adf5fdda9a119cf Mon Sep 17 00:00:00 2001 From: Sai Nallani Date: Tue, 2 Sep 2025 13:17:10 -0400 Subject: [PATCH] Added a way to filter through First Year Courses. More specifically, under the special filters, I added an OTF filter where courses that are "Not Open to First Year Undergraduates" are filtered. --- controllers/endpoints/search.js | 13 ++++++++++++- public/scripts/suggest.js | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/endpoints/search.js b/controllers/endpoints/search.js index db5ad34..9b3651b 100644 --- a/controllers/endpoints/search.js +++ b/controllers/endpoints/search.js @@ -85,6 +85,9 @@ router.use('/:query', function (req, res) { courseQuery['track'] = 'UGRD' } else if (thisQueryWord === 'GRAD') { courseQuery['track'] = 'GRAD' + } else if (thisQueryWord === 'OTF') { + // Mark pseudo-filter to be applied after fetching. + courseQuery.OTF = true } else if ((matches = catalogNumberLevel.exec(thisQueryWord)) !== null) { catalogNumberQueriedLevels.push(parseInt(matches[0].charAt(0)) * 100) } else if ((matches = courseDeptNumberRegexp.exec(thisQueryWord)) !== null) { @@ -207,7 +210,9 @@ router.use('/:query', function (req, res) { } // Construct the courseModel database query as a promise - promises.push(courseModel.find(courseQuery, courseProjection).exec()) + const dbCourseQuery = Object.assign({}, courseQuery) + if (dbCourseQuery.OTF) delete dbCourseQuery.OTF + promises.push(courseModel.find(dbCourseQuery, courseProjection).exec()) promiseNames.push('courses') // Construct the instructorModel database query as a promise @@ -239,6 +244,12 @@ router.use('/:query', function (req, res) { instructors = [] } + // Post-fetch pseudo filters + if (courseQuery.OTF) { + const froshBlockRegex = /NOT\s+OPEN\s+TO\s+FIRST\s+YEAR\s+UNDERGRADUATES/i + courses = courses.filter(c => !c.otherrequirements || !froshBlockRegex.test(c.otherrequirements)) + } + // Filter returned courses to include only the courses that include all of the query terms // Define the properties in which all of the query terms must occur const filteringProperties = ['title', 'department', 'catalogNumber'] diff --git a/public/scripts/suggest.js b/public/scripts/suggest.js index d6ead00..bb44bb3 100644 --- a/public/scripts/suggest.js +++ b/public/scripts/suggest.js @@ -141,7 +141,8 @@ const filters = [ 'label': 'Special', 'options': { '*': 'All courses', - 'NEW': 'New course' + 'NEW': 'New course', + "OTF": "Open to first-year undergraduates" }, 'props': { 'clearall': 1