anchor.diff:              ?ClientError({"Bad sort field", Else})
       end.
   
  -sort_fun(integer,Ti,Ci,<<"desc">>) -> sort_fun(number,Ti,Ci,<<"desc">>);
  -sort_fun(decimal,Ti,Ci,<<"desc">>) -> sort_fun(number,Ti,Ci,<<"desc">>);
  -sort_fun(float,Ti,Ci,<<"desc">>) ->   sort_fun(number,Ti,Ci,<<"desc">>);
  -sort_fun(number,Ti,Ci,<<"desc">>) ->
  +sort_fun(atom,Ti,Ci,<<"desc">>) -> 
  +    fun(X) -> 
  +        case element(Ci,element(Ti,X)) of 
  +            A when is_atom(A) ->
  +                [ -Item || Item <- atom_to_list(A)] ++ [?MaxChar];
  +            _ ->
  +                element(Ci,element(Ti,X))
  +        end
  +    end;
  +sort_fun(binstr,Ti,Ci,<<"desc">>) -> 
  +    fun(X) -> 
  +        case element(Ci,element(Ti,X)) of 
  +            B when is_binary(B) ->
  +                [ -Item || Item <- binary_to_list(B)] ++ [?MaxChar];
  +            _ ->
  +                element(Ci,element(Ti,X))
  +        end
  +    end;
  +sort_fun(boolean,Ti,Ci,<<"desc">>) ->
       fun(X) -> 
           V = element(Ci,element(Ti,X)),
  -        case is_number(V) of
  -            true ->         (-V);
  -            false ->        element(Ci,element(Ti,X))
  +        case V of
  +            true ->         false;
  +            false ->        true;
  +            _ ->            element(Ci,element(Ti,X))
           end 
       end;
   sort_fun(datetime,Ti,Ci,<<"desc">>) -> 
  
positive.code:                 element(Ci,element(Ti,X))
          end
      end;
  sort_fun(Type,_Ti,_Ci,<<"desc">>) ->
      ?SystemException({"Unsupported datatype for sort desc", Type});
  sort_fun(_Type,Ti,Ci,_) -> 
  
negative.code:                 element(Ci,element(Ti,X))
          end
      end;
  sort_fun(number,Ti,Ci,<<"desc">>) ->
      fun(X) -> 
          V = element(Ci,element(Ti,X)),
          case is_number(V) of
              true ->         (-V);
              false ->        element(Ci,element(Ti,X))
          end 
      end;
  sort_fun(string,Ti,Ci,<<"desc">>) -> 
      fun(X) -> 
          case element(Ci,element(Ti,X)) of 
  