aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib/getSearchResults.js
blob: fafbd0b36911edcd3a465830a8779735fdb1351c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;