Server Side Sorting
Request that the server sort results before returning them to the client. See RFC 2891. The SortKey class accepts three parameters that control the sorting:
- attributeDescription - name of the attribute to sort on
- matchingRuleId - matching rule defined by RFC 3698; optional, if not present the attribute’s default matching rule is used
- reverseOrder - whether the entries should be presented in reverse sorted order; default is false
SearchOperation search = new SearchOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
SearchRequest request = SearchRequest.builder()
.dn("dc=ldaptive,dc=org")
.filter("(givenName=d*)")
.returnAttributes("cn", "sn")
.controls(new SortRequestControl(new SortKey[] {new SortKey("sn", "caseExactMatch")}, true)) // sort by surname
.build();
SearchResponse response = search.execute(request);
for (LdapEntry entry : response.getEntries()) {
// do something useful with the entry
}