anchor.diff:      end.
   
   %% @doc Execute preview in the order defined by the list of searchstrategies.
  --spec preview_execute(atom(), integer(), atom(), list(), binary(), integer(), function(), atom()) -> list().
  -preview_execute(_IndexTable, _ID, _Type, [], _SearchTerm, _Limit, _Iff, _PrevStrategy) -> [];
  -preview_execute(_IndexTable, _ID, _Type, _Strategies, _Term, Limit, _Iff, _PrevStrategy) when Limit =< 0 -> [];
  -preview_execute(IndexTable, ID, Type, [exact_match | SearchStrategies], SearchTerm, Limit, Iff, undefined) ->
  +-spec preview_execute(atom(), integer(), atom(), list(), binary(), integer(), function(), atom(), tuple()) -> list().
  +preview_execute(_IndexTable, _ID, _Type, [], _SearchTerm, _Limit, _Iff, _PrevStrategy, _FromStu) -> [];
  +preview_execute(_IndexTable, _ID, _Type, _Strategies, _Term, Limit, _Iff, _PrevStrategy, _FromStu) when Limit =< 0 -> [];
  +preview_execute(IndexTable, ID, Type, [exact_match | SearchStrategies], SearchTerm, Limit, Iff, undefined, FromStu) ->
       {atomic, ResultExact} =
           imem_if:transaction(fun() -> preview_exact(IndexTable, ID, Type, SearchTerm, ?SMALLEST_TERM, Limit, Iff) end),
  -    ResultExact ++ preview_execute(IndexTable, ID, Type, SearchStrategies, SearchTerm, Limit - length(ResultExact), Iff, exact_match);
  -preview_execute(IndexTable, ID, Type, [head_match | SearchStrategies], SearchTerm, Limit, Iff, PrevStrategy) ->
  -    StartingStu = create_starting_stu(Type, ID, head_match, SearchTerm),
  +    ResultExact ++ preview_execute(IndexTable, ID, Type, SearchStrategies, SearchTerm, Limit - length(ResultExact), Iff, exact_match, FromStu);
  +preview_execute(IndexTable, ID, Type, [head_match | SearchStrategies], SearchTerm, Limit, Iff, PrevStrategy, FromStu) ->
  +    StartingStu = if FromStu == <<>> -> create_starting_stu(Type, ID, head_match, SearchTerm);
  +                     true -> FromStu
  +    end,
       IffAndNotAdded = add_filter_duplicated(PrevStrategy, SearchTerm, Iff),
       {atomic, ResultHead} =
           imem_if:transaction(fun() -> preview_head(IndexTable, ID, Type, SearchTerm, StartingStu, Limit, IffAndNotAdded) end),
       case lists:member(body_match, SearchStrategies) of
           true ->
  -            ResultHead ++ preview_execute(IndexTable, ID, Type, [body_match], SearchTerm, Limit - length(ResultHead), Iff, head_match);
  +            ResultHead ++ preview_execute(IndexTable, ID, Type, [body_match], SearchTerm, Limit - length(ResultHead), Iff, head_match, FromStu);
           false ->
               ResultHead
       end;
  -preview_execute(IndexTable, ID, Type, [body_match | _SearchStrategies], SearchTerm, Limit, Iff, PrevStrategy) ->
  -    StartingStu = create_starting_stu(Type, ID, body_match, SearchTerm),
  +preview_execute(IndexTable, ID, Type, [body_match | _SearchStrategies], SearchTerm, Limit, Iff, PrevStrategy, FromStu) ->
  +    StartingStu = if FromStu == <<>> -> create_starting_stu(Type, ID, body_match, SearchTerm);
  +                     true -> FromStu
  +    end,
       IffNotAdded = add_filter_duplicated(PrevStrategy, SearchTerm, Iff),
       {atomic, ResultBody} =
           imem_if:transaction(fun() -> preview_body(IndexTable, ID, Type, SearchTerm, StartingStu, Limit, IffNotAdded) end),
  
positive.code:             preview_range(IndexTable, ID, Type, {NormStart, NormEnd}, Limit, Iff)
      end;
  preview(IndexTable,ID,Type,SearchStrategies,SearchTerm,Limit,Iff,Vnf) ->
      case Vnf(SearchTerm) of
          [?nav] -> [];
          [NormalizedTerm | _] ->
              case is_regexp_search(SearchStrategies, NormalizedTerm) of
                  true ->
                      preview_regexp(IndexTable, ID, Type, NormalizedTerm, Limit, Iff);
                  false ->
                      FilteredStrategies = [Strategy || Strategy <- SearchStrategies, Strategy =/= re_match],
                      preview_execute(IndexTable, ID, Type, FilteredStrategies, NormalizedTerm, Limit, Iff, undefined)
              end
      end.
      % [{exact_match,<<"Key0">>,<<"Value0">>,{ID,<<"Value0">>,<<"Key0">>}}
      % ,{head_match,<<"Key1">>,<<"Value1">>,{ID,<<"Value1">>,<<"Key1">>}}
      % ,{body_match,<<"Key2">>,<<"Value2">>,{ID,<<"Value2">>,<<"Key2">>}}
  
negative.code:     end;
  is_regexp_search(_SearchStrategies, _SearchTerm) -> false.
  
  -spec preview_regexp_init(atom(), integer(), atom(), term(), integer(), function(), tuple() | <<>>) -> list().
  preview_regexp_init(IndexTable, ID, Type, SearchTerm, Limit, Iff, FromStu) ->
      StartingStu = if FromStu == <<>> -> create_starting_stu(Type, ID, re_match, SearchTerm);
                       true -> FromStu
      end,
      ReplacedStar = binary:replace(SearchTerm, [<<"*">>], <<"%">>, [global]),
      ReplacedMark = binary:replace(ReplacedStar, [<<"?">>], <<"_">>, [global]),
      Pattern = imem_sql_funs:like_compile(ReplacedMark),
  