Platform SDK: Active Directory, ADSI, and Directory Services

Sorting the Search Results

The ADS_SEARCHPREF_SORT_ON preference tells the server to sort the result set. Use the ADS_SORTKEY structure to specify the attribute on which to sort.

It is recommended that you specify an indexed attribute. Otherwise, the server must retrieve the complete result set and sort it before sending any results to the client. This also applies to paged searches. Note that you will increase performance of a sorted search if the filter includes an indexed attribute and that attribute is specified as the sort key (in this case, Active Directory can satisfy the sort while processing the filter). For example, an efficient sort query for a set of users could have a filter that included (sn>smith) and a sort key of sn.

You should use sorting only if you really need it.

The default is for sorting to be off.