anchor.diff:                  {lor, _N} ->
                       io:format("lor: ~p: ~p~n", [Node, Out]),
                       Terms = lists:reverse(lists:map(fun(OutNode) ->
  +                        io:format("lor: outnode = ~p~n", [OutNode]),
                           graph_as_query(G, OutNode, Acc)
                       end, Out)),
  -                    NodeCounts = compute_node_counts(G, Out),
  -                    io:format("NodeCounts = ~p~n", [NodeCounts]), %% todo: move to optimize function 
                       {node, {lor, Terms}, node()}; %% todo: real node?
                   {term, {I, F, T}} ->
                       % todo: fix counts (until then, everyone has a 1 count)
  +                    % todo: fix faceting
                       NodeWeights = lists:reverse(lists:usort(lists:map(fun({node, N1}) ->
                           {node_weight, N1, 1}
                       end, Out))),
  
positive.code:                             V -> RAcc ++ V
                          end
                      end, [], Out);
                  X ->
                      io:format("X? ~p: ~p~n", [Node, Out]),
                      {x, X}
              end
      end.
  
  compute_node_counts(G, Terms) ->
      lists:foldl(fun(T, Acc) ->
          lists:map(fun({node, N}) ->
              case proplists:is_defined(N, Acc) of
                  true ->
                      {N, TL} = proplists:lookup(N, Acc),
                      proplists:delete(N, Acc) ++ {N, lists:flatten(TL ++ [T])};
                  false -> Acc ++ {N, [T]}
              end
          end, digraph:out_neighbours(G, T))
      end, [], Terms).
  
  %
  % optimize_terms(Graph, RootNode)
  
negative.code: optimize_query(OpList) ->
      G = query_as_graph(OpList),
      
      %% optimize_junction: AND, OR optimization
      JunctionOps = 
          digraph:out_neighbours(G, or_ops) ++
          digraph:out_neighbours(G, and_ops),
      io:format("JunctionOps = ~p~n", [JunctionOps]),
  
      lists:foreach(fun(JunctionNode) ->
          optimize_junction(G, JunctionNode)
      end, JunctionOps),
      
      OpList2 = graph_as_query(G, root, []),
      io:format("~n----original query OpList: ~n"),
      io:format("OpList  = ~p~n", [OpList]),
      io:format("~n----optimized query OpList: ~n"),
      io:format("OpList2 = ~p~n", [OpList2]),
      io:format("~n----~n"),
      [OpList2].
  