Closed matheushent closed 8 months ago
my first draft is
public Stream<UserModel> searchForMembersStream(
String search, Integer firstResult, Integer maxResults) {
// Split the search string into individual search terms
String[] searchTerms = search.split(",");
// TODO: This could be optimized for large member lists with a query
return getMembersStream()
.filter(
(m) -> {
if (searchTerms.length == 0 || searchTerms[0].isEmpty()) return true;
// Check if any of the search terms match any user attribute
for (String term : searchTerms) {
term = term.trim().toLowerCase(); // Remove leading/trailing spaces and convert to lowercase
if ((m.getEmail() != null && m.getEmail().toLowerCase().contains(term))
|| (m.getUsername() != null && m.getUsername().toLowerCase().contains(term))
|| (m.getFirstName() != null && m.getFirstName().toLowerCase().contains(term))
|| (m.getLastName() != null && m.getLastName().toLowerCase().contains(term))) {
return true; // User matches at least one search term
}
}
return false; // User does not match any search terms
})
.skip(firstResult)
.limit(maxResults);
}
I just wonder it can be inefficient for many users in the string
@matheushent Is there an example of multi-user search anywhere in the Keycloak Admin API? In general, we try to follow the conventions established there, but I'm willing to add if there is a compelling use case.
indeed, there's no such a thing in the Keycloak admin api in general, which I think is a miss TBH. In my case, the use case is simply to speed up a general search I do on Keycloak to know if a list of users belong to an organization. Right now I'm implementing the parallelism at my application level.
@matheushent Thanks. We'll look at a PR. Please make sure it includes a test.
Awesome feature request! can't wait to use this bulk search API :)
fixed in #208
I'd like to request the option to search for a list of input members instead of single searching. Currently, we can do something similar to
GET /realms/{realm}/orgs/{orgId}/members?search=matheus
. I mean, it'd be very cool if we can do something likeGET /realms/{realm}/orgs/{orgId}/members?search=matheus,john.doe,jane
.I believe it wouldn't be that big of a deal, just need to work on this function.