diff --git a/controllers/endpoints/search.js b/controllers/endpoints/search.js index f8a4716..f27a1b4 100644 --- a/controllers/endpoints/search.js +++ b/controllers/endpoints/search.js @@ -88,6 +88,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) { @@ -211,6 +214,10 @@ router.use('/:query', function (req, res) { } // Construct the courseModel database query as a promise + const dbCourseQuery = Object.assign({}, courseQuery) + if (dbCourseQuery.OTF) delete dbCourseQuery.OTF + promises.push(courseModel.find(dbCourseQuery, courseProjection).exec()) + const COURSE_LIMIT = parseInt(process.env.SEARCH_COURSE_LIMIT || '150', 10) const courseFindQuery = courseModel .find(courseQuery, courseProjection) @@ -255,6 +262,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