anchor.diff:  %% Internal functions
   %%----------------------------------------------------------------------------
   
  +%% convert string to query
   from_str(Str, Lang) ->
       {ok, ParseTree} = dk_q_parser:parse(scan(Str)),
  -    compress(tree_to_query(ParseTree, Lang)).
  +    tree_to_query(ParseTree, Lang).
   
   scan(<<C/utf8, Rest/bytes>>) ->
       case C of
  
positive.code: tree_to_query({not_q, SubTree}, Lang) ->
      #not_q{sub = tree_to_query(SubTree, Lang)};
  tree_to_query({term_q, {string, Keyword, _}}, Lang) ->
      case dk_pp:terms(Keyword, Lang) of
          [] ->
              #or_q{subs = []};
          [Term | _]  ->
              #term_q{term = Term}
      end.
  
  compress(#and_q{subs = Qs}) ->
      {Ands, Rest} = lists:partition(fun (X) -> is_record(X, and_q) end,
                                     [compress(Q) || Q <- Qs]),
      #and_q{subs = lists:flatten([subs(Q) || Q <- Ands]) ++ Rest};
  compress(#or_q{subs = Qs}) ->
      {Ors, Rest} = lists:partition(fun (X) -> is_record(X, or_q) end,
                                    [compress(Q) || Q <- Qs]),
      #or_q{subs = lists:flatten([subs(Q) || Q <- Ors]) ++ Rest};
  compress(Q = #not_q{}) ->
      Q;
  compress(Q = #term_q{}) ->
      Q.
  
  subs(#and_q{subs = Qs}) ->
      Qs;
  subs(#or_q{subs = Qs}) ->
      Qs;
  subs(Q = #not_q{}) ->
      [Q];
  subs(Q = #term_q{}) ->
      [Q].
  
  dnf(#and_q{subs = Qs}) ->
      Product = product([subs(dnf(Q)) || Q <- Qs]),
      #or_q{subs = [#and_q{subs = Rs} || Rs <- Product]};
  dnf(#or_q{subs = Qs}) ->
      #or_q{subs = [dnf(Q) || Q <- Qs]};
  dnf(Q = #not_q{sub = #term_q{}}) ->
      Q;
  dnf(#not_q{sub = #not_q{sub = Q}}) ->
      dnf(Q);
  dnf(#not_q{sub = #or_q{subs = Qs}}) ->
      dnf(#and_q{subs = [#not_q{sub = dnf(Q)} || Q <- Qs]});
  dnf(#not_q{sub = #and_q{subs = Qs}}) ->
      #or_q{subs = [#not_q{sub = dnf(Q)} || Q <- Qs]};
  dnf(Q = #term_q{}) ->
      Q.
  
  product([Xs, Ys | Rest]) ->
      product(Rest, [[X, Y] || X <- Xs, Y <- Ys]).
  
  product([], Acc) ->
      Acc;
  product([L], Acc) ->
      [[H | T] || H <- L, T <- Acc];
  product([L | Rest], Acc) ->
      product(Rest, [[H | T] || H <- L, T <- Acc]).
  
  
negative.code:         $| -> [{'|', 1} | scan(Rest)];
          $! -> [{'!', 1} | scan(Rest)];
          32 -> scan(Rest); % skip spaces
          _ ->
              Regex = [<<"^([^()&|! ]*)(.*)$">>],
              Options = [unicode, global, {capture, all_but_first,
                                           binary}],
  