From 62469172fa7ff2a1136902bcda9e5f546f2d06f9 Mon Sep 17 00:00:00 2001 From: Drew Volz Date: Sun, 25 Feb 2018 16:57:55 -0700 Subject: [PATCH] Course search enhancements * Fuzzy search * Search titles --- package.json | 1 + source/views/sis/course-search/search.js | 4 +++- yarn.lock | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f5314f436..6bc0129b38 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "css-select": "1.2.0", "delay": "2.0.0", "events": "2.0.0", + "fuzzysearch": "1.0.3", "get-urls": "7.2.0", "glamorous-native": "1.3.0", "html-entities": "1.2.1", diff --git a/source/views/sis/course-search/search.js b/source/views/sis/course-search/search.js index 27d6ebc796..edad53f04b 100644 --- a/source/views/sis/course-search/search.js +++ b/source/views/sis/course-search/search.js @@ -16,6 +16,7 @@ import {connect} from 'react-redux' import groupBy from 'lodash/groupBy' import sortBy from 'lodash/sortBy' import toPairs from 'lodash/toPairs' +import fuzzysearch from 'fuzzysearch' import {CourseSearchResultsList} from './list' import LoadingView from '../../components/loading' import {deptNum} from './lib/format-dept-num' @@ -124,7 +125,8 @@ class CourseSearchView extends React.PureComponent { const results = this.props.allCourses.filter( course => - course.name.toLowerCase().includes(query) || + fuzzysearch(query, course.name.toLowerCase()) || + fuzzysearch(query, (course.title || '').toLowerCase()) || (course.instructors || []).some(name => name.toLowerCase().includes(query), ) || diff --git a/yarn.lock b/yarn.lock index fa568fcc7a..eba44a7393 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2531,6 +2531,10 @@ functional-red-black-tree@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" +fuzzysearch@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/fuzzysearch/-/fuzzysearch-1.0.3.tgz#dffc80f6d6b04223f2226aa79dd194231096d008" + gauge@~1.2.5: version "1.2.7" resolved "https://registry.yarnpkg.com/gauge/-/gauge-1.2.7.tgz#e9cec5483d3d4ee0ef44b60a7d99e4935e136d93"