private List < FieldOrder > createImplicitOrderBy ( ) { List < FieldOrder > implicitOrders = new ArrayList <> ( options . fieldOrders ) ; boolean hasDocumentId = false ; if ( implicitOrders . isEmpty ( ) ) { // If no explicit ordering is specified, use the first inequality to define an implicit order. for ( FieldFilter fieldFilter : options . fieldFilters ) { if ( ! fieldFilter . isEqualsFilter ( ) ) { implicitOrders . add ( new FieldOrder ( fieldFilter . fieldPath , Direction . ASCENDING ) ) ; break ; } } } else { for ( FieldOrder fieldOrder : options . fieldOrders ) { if ( fieldOrder . fieldPath . equals ( FieldPath . DOCUMENT_ID ) ) { hasDocumentId = true ; } } } if ( ! hasDocumentId ) { // Add implicit sorting by name, using the last specified direction. Direction lastDirection = implicitOrders . isEmpty ( ) ? Direction . ASCENDING : implicitOrders . get ( implicitOrders . size ( ) - 1 ) . direction ; implicitOrders . add ( new FieldOrder ( FieldPath . documentId ( ) , lastDirection ) ) ; } return implicitOrders ; }
Computes the backend ordering semantics for DocumentSnapshot cursors .