directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamsin Slinn <tam.sl...@gmail.com>
Subject How to do a sorted search using Apache Directory API
Date Thu, 07 Mar 2019 09:40:49 GMT
Hi,
I hope this is an OK question to post to the list.

I'm running the code below against OpenLDAP 2.4.40. I based the code on an
integration test for SortRequestControl. However, this code does not return
the entries in the order I expect (alphabetical by sn). Can you tell me
what I am missing?
Thanks for any help!

    SearchRequest req = new SearchRequestImpl();
    req.setScope(SearchScope.ONELEVEL);
    req.addAttributes("*");
    req.setTimeLimit(0);
    req.setBase(searchDn);
    req.setFilter("(objectclass=posixAccount)");

    SortRequest sortRequest = new SortRequestControlImpl();
    sortRequest.addSortKey(new SortKey("sn"));
    req.addControl(sortRequest);

   try (SearchCursor cursor = connection.search(req)) {
         while (cursor.next()) {
                SearchResultEntry se = (SearchResultEntry) cursor.get();
                Entry entry = se.getEntry();
                System.out.println("sn: " + entry.get("sn").getString());

        }
    }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message