Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions controllers/endpoints/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']
Expand Down
3 changes: 2 additions & 1 deletion public/scripts/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down