anchor.diff:              Search#search_sql{where=C ++ " AND " ++ Clause}
       end.
   
  +
   %% Add an AND clause to the WHERE of a #search_sql
  -add_order(Clause, Search) ->
  +add_order(Sort, Search) ->
  +    Clause = case Sort of 
  +                 "random" ->
  +                     "random()";
  +                 _ -> 
  +                     [FirstChar|F1] = Sort,
  +                     case FirstChar of
  +                         $- -> sql_safe(F1) ++ " DESC";
  +                         $+ -> sql_safe(F1) ++ " ASC";
  +                         _ -> sql_safe(Sort) ++ " ASC"
  +                     end
  +             end,
       case Search#search_sql.order of
           [] ->
               Search#search_sql{order=Clause};
  
positive.code:                 true -> atom_to_list(Sort);
                  false -> Sort
              end,
      [FirstChar|F1] = Sort1,
      Order = case FirstChar of
                  $- -> F1 ++ " DESC";
                  $+ -> F1 ++ " ASC";
                  _ -> Sort1 ++ " ASC"
              end,
      parse_query(Rest, Context, add_order(Order, Result));
  
  %% custompivot=tablename
  %% Add a join on the given custom pivot table.
  
negative.code: ]).
  
  -include_lib("zotonic.hrl").
  
  -define(SQL_SAFE_REGEXP, "^[a-zA-Z_\.]+$").
  
  search(Query, Context) ->
      Start = #search_sql{select="rsc.id",
  