Sorting

The sort method

The Module class sort method is used to order a set of matching records once the search of a module has been run.

Arguments

This sort method takes two arguments:

  • columns

    The columns argument is used to specify the columns by which to sort the result set. The argument can be either a String, String[] or a ArrayList<String>. Each string can be a simple column name or a set of column names, separated by semi-colons or commas.

    Each column name can be preceded by a + (plus) or - (minus or dash). A leading + indicates that the records should be sorted in ascending order. A leading - indicates that the records should be sorted in descending order.

    Note: If a sort order ("+" or "-") is not given, the sort order defaults to ascending.

  • flags

    The flags argument is used to pass one or more flags to control the way the sort is carried out. As with the columns argument, the flags argument can be either a String, String[] or a ArrayList<String>. Each String can be a single flag or a set of flags separated by semi-colons or commas.

    The following flags control the type of comparisons used when sorting:

    • word-based

      Sort disregards all punctuation and white spaces (more than the one space between words). For example:

      Traveler's        Inn

      will be sorted as

      Travelers Inn
    • full-text

      Sort includes all punctuation and white spaces. For example:

      Traveler's        Inn

      will be sorted as

      Traveler's        Inn

      and will therefore differ from:

      Traveler's Inn
    • compress-spaces

      Sort includes punctuation but disregards all white space (with the exception of a single space between words). For example:

      Traveler's        Inn

      will be sorted as

      Traveler's Inn

      Note: If none of these flags is included, the comparison defaults to word-based.

    The following flags modify the sorting behaviour:

    • case-sensitive

      Sort is sensitive to upper and lower case. For example:

      Melbourne gallery

      will be sorted separately to

      Melbourne Gallery
    • order-insensitive

      Values in a multi-value field will be sorted alphabetically regardless of the order in which they display. For example, a record which has the following values in the NamRoles_tab column in this order:

      1. Collection Manager
      2. Curator
      3. Internet Administrator

      and another record which has the values in this order:

      1. Internet Administrator
      2. Collection Manager
      3. Curator

      will be sorted the same.

    • null-low

      Records with empty columns will be placed at the start of the result set rather than at the end.

    • extended-sort

      Values that include diacritics will be sorted separately to those that do not. For example:

      entrée

      will be sorted separately to

      entree

    The following flags can be used when generating a summary of the sorted records:

    • report

      A summary of the sort is generated. The summary report is a hierarchically structured object that summarises the number of unique values contained in the sort columns. See Return Value and Example for a description and illustration of the returned structure.

    • table-as-text

      All data from multi-valued columns will be treated as a single value (joined by line break characters) in the summary results array. For example, for a record which has the following values in the NamRoles_tab column:

      Collection Manager, Curator, Internet Administrator

      the summary will include statistics for a single value:

      Collection Manager
      Curator
      Internet Administrator

      Thus the number of values in the summary results display will match the number of records.

      If this option is not included, each value in a multi-valued column will be treated as a distinct value in the summary. Thus there may be many more values in the summary results than there are records.

For example:

  1. Sort parties by first name (ascending):
    Module parties = new Module("eparties", session);
    Terms search = new Terms();
    search.add("NamLast", "Smith");
    long hits = parties.findTerms(search);
    
    parties.sort("NamFirst");
    
  2. Sort parties by title (ascending) and then first name (descending):
    String[] sort =
    {
        "NamTitle",
        "-NamFirst"
    };
    parties.sort(sort);
    
  3. Run a case-sensitive sort of parties by title (ascending) and then first name (descending):

    String[] sort =
    {
        "NamTitle",
        "-NamFirst"
    };
    String[] flags =
    {
        "case-sensitive",
    };
    parties.sort(sort, flags);