Merge pull request #6661 from HJianBo/fix-client-fuzzy-matching-for-5
chore: client searching support \[]()* chars
This commit is contained in:
commit
19dd5a7c97
|
@ -288,28 +288,20 @@ ms(lifetime, X) ->
|
||||||
%% Fuzzy filter funcs
|
%% Fuzzy filter funcs
|
||||||
|
|
||||||
fuzzy_filter_fun(Fuzzy) ->
|
fuzzy_filter_fun(Fuzzy) ->
|
||||||
REFuzzy = lists:map(fun({K, like, S}) ->
|
|
||||||
{ok, RE} = re:compile(escape(S)),
|
|
||||||
{K, like, RE}
|
|
||||||
end, Fuzzy),
|
|
||||||
fun(MsRaws) when is_list(MsRaws) ->
|
fun(MsRaws) when is_list(MsRaws) ->
|
||||||
lists:filter( fun(E) -> run_fuzzy_filter(E, REFuzzy) end
|
lists:filter( fun(E) -> run_fuzzy_filter(E, Fuzzy) end
|
||||||
, MsRaws)
|
, MsRaws)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
escape(B) when is_binary(B) ->
|
|
||||||
re:replace(B, <<"\\\\">>, <<"\\\\\\\\">>, [{return, binary}, global]).
|
|
||||||
|
|
||||||
run_fuzzy_filter(_, []) ->
|
run_fuzzy_filter(_, []) ->
|
||||||
true;
|
true;
|
||||||
run_fuzzy_filter(E = {_, #{clientinfo := ClientInfo}, _},
|
run_fuzzy_filter(E = {_, #{clientinfo := ClientInfo}, _},
|
||||||
[{Key, _, RE} | Fuzzy]) ->
|
[{Key, like, SubStr} | Fuzzy]) ->
|
||||||
Val = case maps:get(Key, ClientInfo, "") of
|
Val = case maps:get(Key, ClientInfo, <<>>) of
|
||||||
undefined -> "";
|
undefined -> <<>>;
|
||||||
V -> V
|
V -> V
|
||||||
end,
|
end,
|
||||||
re:run(Val, RE, [{capture, none}]) == match
|
binary:match(Val, SubStr) /= nomatch andalso run_fuzzy_filter(E, Fuzzy).
|
||||||
andalso run_fuzzy_filter(E, Fuzzy).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% format funcs
|
%% format funcs
|
||||||
|
|
|
@ -710,26 +710,19 @@ ms(created_at, X) ->
|
||||||
%% Match funcs
|
%% Match funcs
|
||||||
|
|
||||||
fuzzy_filter_fun(Fuzzy) ->
|
fuzzy_filter_fun(Fuzzy) ->
|
||||||
REFuzzy = lists:map(fun({K, like, S}) ->
|
|
||||||
{ok, RE} = re:compile(escape(S)),
|
|
||||||
{K, like, RE}
|
|
||||||
end, Fuzzy),
|
|
||||||
fun(MsRaws) when is_list(MsRaws) ->
|
fun(MsRaws) when is_list(MsRaws) ->
|
||||||
lists:filter( fun(E) -> run_fuzzy_filter(E, REFuzzy) end
|
lists:filter( fun(E) -> run_fuzzy_filter(E, Fuzzy) end
|
||||||
, MsRaws)
|
, MsRaws)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
escape(B) when is_binary(B) ->
|
|
||||||
re:replace(B, <<"\\\\">>, <<"\\\\\\\\">>, [{return, binary}, global]).
|
|
||||||
|
|
||||||
run_fuzzy_filter(_, []) ->
|
run_fuzzy_filter(_, []) ->
|
||||||
true;
|
true;
|
||||||
run_fuzzy_filter(E = {_, #{clientinfo := ClientInfo}, _}, [{Key, _, RE} | Fuzzy]) ->
|
run_fuzzy_filter(E = {_, #{clientinfo := ClientInfo}, _}, [{Key, like, SubStr} | Fuzzy]) ->
|
||||||
Val = case maps:get(Key, ClientInfo, "") of
|
Val = case maps:get(Key, ClientInfo, <<>>) of
|
||||||
undefined -> "";
|
undefined -> <<>>;
|
||||||
V -> V
|
V -> V
|
||||||
end,
|
end,
|
||||||
re:run(Val, RE, [{capture, none}]) == match andalso run_fuzzy_filter(E, Fuzzy).
|
binary:match(Val, SubStr) /= nomatch andalso run_fuzzy_filter(E, Fuzzy).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% format funcs
|
%% format funcs
|
||||||
|
|
Loading…
Reference in New Issue