================================================================================
ORDER BY Id
================================================================================

FIND {MyName} RETURNING Account(Name, Id ORDER BY Id)

--------------------------------------------------------------------------------

    (source_file
      (sosl_query_body
        (find_clause
          (term_separator_start)
          (term)
          (term_separator_end))
        (returning_clause
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (order_by_clause
              (order_expression
                (field_identifier
                  (identifier))))))))

================================================================================
ORDER BY Multi
================================================================================

FIND {MyContactName}
RETURNING
  Contact(Name, Id ORDER BY Name),
  Account(Description, Id ORDER BY Description)

--------------------------------------------------------------------------------

    (source_file
      (sosl_query_body
        (find_clause
          (term_separator_start)
          (term)
          (term_separator_end))
        (returning_clause
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (order_by_clause
              (order_expression
                (field_identifier
                  (identifier)))))
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (order_by_clause
              (order_expression
                (field_identifier
                  (identifier))))))))

================================================================================
ORDER BY Nulls Last
================================================================================

FIND {MyAccountName} IN NAME FIELDS
RETURNING Account(Name, Id ORDER BY Name DESC NULLS last)

--------------------------------------------------------------------------------

    (source_file
      (sosl_query_body
        (find_clause
          (term_separator_start)
          (term)
          (term_separator_end))
        (in_clause
          (in_type))
        (returning_clause
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (order_by_clause
              (order_expression
                (field_identifier
                  (identifier))
                (order_direction)
                (order_null_direciton)))))))

================================================================================
ORDER BY Nulls First
================================================================================

FIND {MyAccountName} IN NAME FIELDS
RETURNING Account(Name, Id ORDER BY Name DESC NULLS FIRST)

--------------------------------------------------------------------------------

    (source_file
      (sosl_query_body
        (find_clause
          (term_separator_start)
          (term)
          (term_separator_end))
        (in_clause
          (in_type))
        (returning_clause
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (order_by_clause
              (order_expression
                (field_identifier
                  (identifier))
                (order_direction)
                (order_null_direciton)))))))

================================================================================
ORDER BY Distance
================================================================================

FIND {San Francisco}
RETURNING
  My_Custom_Object__c (Name, Id
    WHERE DISTANCE(My_Location_Field__c,GEOLOCATION(37,122),'mi') < 500
    ORDER BY DISTANCE(My_Location_Field__c,GEOLOCATION(37,122),'mi') DESC)

--------------------------------------------------------------------------------

    (source_file
      (sosl_query_body
        (find_clause
          (term_separator_start)
          (term)
          (term_separator_end))
        (returning_clause
          (sobject_return
            (identifier)
            (selected_fields
              (field_identifier
                (identifier))
              (field_identifier
                (identifier)))
            (where_clause
              (comparison_expression
                (function_expression
                  (function_name)
                  (field_identifier
                    (identifier))
                  (geo_location_type
                    (function_name)
                    (decimal)
                    (decimal))
                  (string_literal))
                (value_comparison_operator)
                (int)))
            (order_by_clause
              (order_expression
                (function_expression
                  (function_name)
                  (field_identifier
                    (identifier))
                  (geo_location_type
                    (function_name)
                    (decimal)
                    (decimal))
                  (string_literal))
                (order_direction)))))))