blob: fa012ac836f11a5fe7e6b109335ef2d37eee7f6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import FuzzySearch from 'fuzzy-search';
import uniqBy from 'lodash/uniqBy';
import users from '../users';
function getSearchResults(query) {
const searcher = new FuzzySearch(users.allUsers, ['value', 'alt']);
if (query.trim() === '') {
return [];
}
const allResults = searcher.search(query);
const uniqResults = uniqBy(allResults, result => result.id);
const firstResults = uniqResults.splice(0, 4);
const userIds = firstResults.map(result => result.id);
return userIds;
}
export default getSearchResults;
|