Skip to content

Commit

Permalink
fix: use fusejs to filter user search results
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Feb 6, 2025
1 parent c3733d6 commit 76dd764
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions slack/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export async function searchChannels(webClient, query) {
result?.channels ?? [],
{
keys: ['name'],
threshold: 0.4
threshold: 0.4,
findAllMatches: true
}
)).search(query).map(result => result.item)

Expand Down Expand Up @@ -216,12 +217,14 @@ export async function listUsers(webClient) {

export async function searchUsers(webClient, query) {
const users = await webClient.users.list()
const matchingUsers = users.members.filter(user => {
return user.name.includes(query) ||
user.profile.real_name.includes(query) ||
user.profile.display_name.includes(query)
const fuse = new Fuse(users.members, {
keys: ['name', 'profile.real_name', 'profile.display_name'],
threshold: 0.4,
findAllMatches: true
})
if (matchingUsers.length === 0) {
const matchingUsers = fuse.search(query).map(result => result.item)

if (!matchingUsers || matchingUsers.length === 0) {
console.log('No users found')
return
}
Expand Down

0 comments on commit 76dd764

Please sign in to comment.