anchor.diff:      % ].
   
   %% @doc Preview match scan into an index for finding first "best" matches
  --spec preview(atom(),integer(),atom(),list(),term(),integer(),function(),function(),tuple()) -> list().
  -preview(_IndexTable,_ID,_Type,_SearchStrategies,_SearchTerm,_Limit,_Iff,_Vnf,_Cont) ->
  -    [].     %% ToDo: implement continuation search
  +-spec preview(atom(),integer(),atom(),list(),term(),integer(),function(),function(),map() | tuple()) -> list().
  +preview(IndexTable,ID,Type,SearchStrategies,SearchTerm,Limit,Iff,Vnf, 
  +    #{<<"match_info">> := Match}) ->
  +    {_,_,_, FromStu} = binary_to_term(base64:decode(Match)),
  +    preview(IndexTable,ID,Type,SearchStrategies,SearchTerm,Limit,Iff,Vnf,FromStu);
  +preview(IndexTable,ID,Type,SearchStrategies,SearchTerm,Limit,Iff,Vnf,FromStu) ->
  +    case Vnf(SearchTerm) of
  +        [?nav] -> [];
  +        [NormalizedTerm | _] ->
  +            case is_regexp_search(SearchStrategies, NormalizedTerm) of
  +                true ->
  +                    preview_regexp_init(IndexTable, ID, Type, NormalizedTerm, Limit, Iff, FromStu);
  +                false ->
  +                    FilteredStrategies = [Strategy || Strategy <- SearchStrategies, Strategy =/= re_match],
  +                    preview_execute(IndexTable, ID, Type, FilteredStrategies, NormalizedTerm, Limit, Iff, undefined, FromStu)
  +            end
  +    end.
  +    %% ToDo: implement continuation search
       % [{exact_match,<<"Key0">>,<<"Value0">>,{ID,<<"Value0">>,<<"Key0">>}}
       % ,{head_match,<<"Key1">>,<<"Value1">>,{ID,<<"Value1">>,<<"Key1">>}}
       % ,{body_match,<<"Key2">>,<<"Value2">>,{ID,<<"Value2">>,<<"Key2">>}}
  
positive.code:     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) ->
      {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),
      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);
          false ->
              ResultHead
      end;
  preview_execute(IndexTable, ID, Type, [body_match | _SearchStrategies], SearchTerm, Limit, Iff, PrevStrategy) ->
      StartingStu = create_starting_stu(Type, ID, body_match, SearchTerm),
      IffNotAdded = add_filter_duplicated(PrevStrategy, SearchTerm, Iff),
      {atomic, ResultBody} =
          imem_if:transaction(fun() -> preview_body(IndexTable, ID, Type, SearchTerm, StartingStu, Limit, IffNotAdded) end),
  
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),
  