Overview

Discover users in your community through powerful search and query capabilities. social.plus SDK provides methods to search users by display name and retrieve user collections with various sorting options.
Deleted users are automatically excluded from all search and query results to maintain data integrity.

Search vs Query

Search Users

Find users by display name with keyword matching

Query Users

Retrieve user collections with sorting options

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.

Search Requirements

  • Search keywords must be at least 3 characters long
  • If no keyword is supplied, the list of users will be organized alphabetically by display name
  • 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

Sorting Options

Users have the option to sort by:
  • displayName: Alphabetical sorting using ICU collation for English locale (default)
  • lastCreated: Most recently created users first
  • firstCreated: Oldest users first

Special Character Handling

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:
  • Searching for “Äli” will only return users whose display name contains “Äli” (e.g., “Älise”)
  • Searching for “Alice” will NOT return “Älice”

Search Implementation

var token: AmityNotificationToken?

func searchUserExample() {
    let liveCollection = userRepository.searchUsers("<display-name>", sortBy: .displayName)
    token = liveCollection.observe { collection, change, error in
        // Handle live collection notification here
    }
}

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.

Sorting Behavior

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 Implementation

var token: AmityNotificationToken?

func queryUsersExample() {
    let liveCollection = userRepository.getUsers(.displayName)
    token = liveCollection.observe { collection, change, error in
        // Handle live collection notification here
    }
}

Best Practices

Next Steps