All pages
Powered by GitBook
1 of 1

Search and Query Users

Search User

Query for users by their display name, receiving a collection of AmityUser matching your search. It requires two parameters: the display name you're searching for, and a 'sort option' from the AmityUserSortOption enum. If no keyword is supplied, the list of users will be organized alphabetically by display name.

Users also have the option to sort by lastCreated, firstCreated, or displayName. When a keyword is provided, the list will be arranged based on search rank. The displayName sorting option will be specified by default if it isn't specified.

With the displayName sorting option, users are sorted alphabetically by their display names using ICU collation for the English locale. This means that special characters such as Ä are treated as variants of A. For example, a sorted list might appear as: adam, Älex, Alice, Arthur, charlie, Kristen.

When providing a search keyword, the API performs an exact-match lookup for special characters.

  • For instance, if you search for "Äli", only users whose display name contains the "Äli" characters (e.g., "Älise") will be returned.

  • Conversely, searching for "Alice" will not return "Älice".

  • The search keyword must be at least 3 characters long.

  • Deleted users are excluded from the results

Search users by display name

The code above will provide you with the list of users which matches with display name "Brian".

userRepo.searchUserByDisplayName('Test User 1')

The above example searches for all users whose display names start with "Test User 1".

The queryUsers provides a way to search for users by their display name.

Query Users

Query for users to receive a collection of AmityUser based on a single parameter: a 'sort option' from the AmityUserSortOption enum. Sort the list by options such as displayName, firstCreated, or lastCreated. The displayName sort option will be specified by default if it isn't specified.

With the displayName sorting option, users are sorted alphabetically by their display names using ICU collation for the English locale. This means that special characters such as Ä are treated as variants of A. For example, a sorted list might appear as: adam, Älex, Alice, Arthur, charlie, Kristen.

Deleted users are excluded from the results

Query users
const liveUserCollection = UserRepository.queryUsers({
    keyword?: string, 
    filter?: 'all' | 'flagged', 
    sortBy?: 'lastCreated' | 'firstCreated' | 'displayName'
})

// filter if flagCount is > 0
// lastCreated: sort: createdAt desc 
// firstCreated: sort: createdAt asc 
// displayName: sort: alphanumerical asc

liveUserCollection.on(“dataUpdated”, models => {
  models.map(model => console.log(model.userId))
})

If you wish to observe for changes to a collection of users, you can use liveUsers