Skip to content

Commit 2edadb9

Browse files
committed
feat(webapp/search): use fuzzaldrin for fuzzy search
1 parent e047cd2 commit 2edadb9

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"esnext-coverage": "^0.0.2",
2020
"esnext-coverage-analytics": "^0.0.3",
21+
"fuzzaldrin": "^2.1.0",
2122
"redux": "^3.6.0",
2223
"url-parse": "^1.1.3",
2324
"virtual-dom": "^2.1.1"

src/webapp/components/search/search.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import h from 'virtual-dom/h';
22
import store from '../../store';
3+
import search from '../../services/search';
34

45
function suggestionsSelector(state) {
5-
const current = state.location.path[0];
6-
return Object
6+
const query = state.search;
7+
if (!query) { return []; }
8+
const currentLocation = state.location.path[0];
9+
const candidates = Object
710
.keys(state.files.contents)
8-
.filter(fileName => {
9-
return state.search && current !== fileName && fileName.includes(state.search);
10-
});
11+
.filter(fileName => fileName !== currentLocation);
12+
return search(candidates, query, {maxResults: 7});
1113
}
1214

1315
function clearSearch() {
@@ -50,7 +52,7 @@ function searchSuggestionList(suggestions) {
5052
}, suggestions.map(searchSuggestion));
5153
}
5254

53-
export default function search(state) {
55+
export default function searchComponent(state) {
5456
return h('div', {
5557
className: 'search'
5658
}, [

src/webapp/services/search.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {filter} from 'fuzzaldrin';
2+
3+
export default function search(candidates, query, options) {
4+
return filter(candidates, query, options);
5+
}

0 commit comments

Comments
 (0)