• Document Sorted

    By Ivan Giannattasio 3 years ago

    Hi,
    i need to sort a document collection on one field in ascending or descending mode.
    I read there is a specific object called Document Sorter to do it.
    But i don't find example or documentation.
    How can i do?
    Can you help me?

    Thanks
    Ivan Giannattasio

    • By Ivan Giannattasio 3 years ago

      I add more details. I need to sort DocumentCollection from dql search.
      I've just tried intersect with a viewentrycollection, but with big query the performance are too slow!

    • By Jesse Gallagher 3 years ago

      I haven't personally used it, but the org.openntf.domino.helpers.DocumentSorter class looks like what you're talking about. You'd use it like:

      DocumentSorter sorter = new DocumentSorter(docColl, Arrays.asList("LastName"));
      DocumentCollection sorted = sorter.sort();
      

      You could probably then get reverse ordering by using:

      List<Document> docs = new ArrayList<>(sorted);
      Collections.reverse(docs);
      

      That said, I think it's likely that performance wouldn't necessarily be better than what you're seeing without it - the sorting loads each document in the collection to read the fields and has no special acceleration from Domino.