Skip to content

When a sort control is used with a paging control, the result set is not sorted. #325

Closed

Description

@trainKing-star

I used the UnboundID LDAP SDK to access the local OpenDJ server.

    <dependency>
      <groupId>com.unboundid</groupId>
      <artifactId>unboundid-ldapsdk</artifactId>
      <version>6.0.9</version>
    </dependency>

When only the sorting control is used, the sorting can be normally performed.

        final LDAPConnection connection = new LDAPConnection();
        connection.connect("127.0.0.1", 389, 1000);
        connection.bind("uid=test,cn=users,dc=example,dc=com", "test");
        SearchRequest searchRequest ;
        try {
            searchRequest = new SearchRequest("ou=page,ou=test,dc=example,dc=com", SearchScope.SUB, "uid=1*");
            searchRequest.addControl(new ServerSideSortRequestControl(new SortKey("uid", true)));
            SearchResult searchResult = connection.search(searchRequest);
            System.out.println("resultSize: " + searchResult.getEntryCount());
            for (SearchResultEntry searchEntry : searchResult.getSearchEntries()) {
                System.out.println(searchEntry);
            }
        } catch (LDAPException e) {
            throw new RuntimeException(e);
        }

The following result is returned:

resultSize: 1111
SearchResultEntry(dn='uid=1999,ou=page,ou=test
SearchResultEntry(dn='uid=1998,ou=page,ou=test
SearchResultEntry(dn='uid=1997,ou=page,ou=test
SearchResultEntry(dn='uid=1996,ou=page,ou=test
SearchResultEntry(dn='uid=1995,ou=page,ou=test
SearchResultEntry(dn='uid=1994,ou=page,ou=test
SearchResultEntry(dn='uid=1993,ou=page,ou=test
SearchResultEntry(dn='uid=1992,ou=page,ou=test
SearchResultEntry(dn='uid=1991,ou=page,ou=test
SearchResultEntry(dn='uid=1990,ou=page,ou=test
SearchResultEntry(dn='uid=199,ou=page,ou=test
SearchResultEntry(dn='uid=1989,ou=page,ou=test
SearchResultEntry(dn='uid=1988,ou=page,ou=test
SearchResultEntry(dn='uid=1987,ou=page,ou=test
SearchResultEntry(dn='uid=1986,ou=page,ou=test
SearchResultEntry(dn='uid=1985,ou=page,ou=test
SearchResultEntry(dn='uid=1984,ou=page,ou=test
SearchResultEntry(dn='uid=1983,ou=page,ou=test
SearchResultEntry(dn='uid=1982,ou=page,ou=test
SearchResultEntry(dn='uid=1981,ou=page,ou=test
··············································

When the sort control is used with the paging control, the sort is invalid.

        final LDAPConnection connection = new LDAPConnection();
        connection.connect("127.0.0.1", 389, 1000);
        connection.bind("uid=test,cn=users,dc=example,dc=com", "test");
        SearchRequest searchRequest ;
        try {
            searchRequest = new SearchRequest("ou=page,ou=test,dc=example,dc=com", SearchScope.SUB, "uid=1*");
            searchRequest.addControl(new ServerSideSortRequestControl(new SortKey("uid", true)));
            searchRequest.setControls(new SimplePagedResultsControl(10, null));
            SearchResult searchResult = connection.search(searchRequest);
            System.out.println("resultSize: " + searchResult.getEntryCount());
            for (SearchResultEntry searchEntry : searchResult.getSearchEntries()) {
                System.out.println(searchEntry);
            }
        } catch (LDAPException e) {
            throw new RuntimeException(e);
        }

The following result is returned:

resultSize: 10
SearchResultEntry(dn='uid=1,ou=page,ou=test
SearchResultEntry(dn='uid=10,ou=page,ou=test
SearchResultEntry(dn='uid=11,ou=page,ou=test
SearchResultEntry(dn='uid=12,ou=page,ou=test
SearchResultEntry(dn='uid=13,ou=page,ou=test
SearchResultEntry(dn='uid=14,ou=page,ou=test
SearchResultEntry(dn='uid=15,ou=page,ou=test
SearchResultEntry(dn='uid=16,ou=page,ou=test
SearchResultEntry(dn='uid=17,ou=page,ou=test
SearchResultEntry(dn='uid=18,ou=page,ou=test

Does OpenDj support paging after server-side sorting?

Activity

  1. vharseko commented on Aug 5, 2024

    @vharseko
    Member

    try

    searchRequest
        .addControl(new ServerSideSortRequestControl(new SortKey("uid", true)))
        .addControl(new SimplePagedResultsControl(10, null))
    ;
    
  2. added a commit that references this issue on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions