|
|
@ -1083,18 +1083,28 @@ defmodule Explorer.Chain do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec search_token(String.t()) :: [Token.t()] |
|
|
|
defp prepare_search_term(string) do |
|
|
|
def search_token(word) do |
|
|
|
case Regex.scan(~r/[a-zA-Z0-9]+/, string) do |
|
|
|
term = |
|
|
|
[_ | _] = words -> |
|
|
|
word |
|
|
|
term_final = |
|
|
|
|> String.replace(~r/[^a-zA-Z0-9]/, " ") |
|
|
|
words |
|
|
|
|> String.replace(~r/ +/, " & ") |
|
|
|
|> Enum.map(fn [word] -> word <> ":*" end) |
|
|
|
|
|
|
|
|> Enum.join(" & ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:some, term_final} |
|
|
|
|
|
|
|
|
|
|
|
term_final = term <> ":*" |
|
|
|
_ -> |
|
|
|
|
|
|
|
:none |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@spec search_token(String.t()) :: [Token.t()] |
|
|
|
|
|
|
|
def search_token(string) do |
|
|
|
|
|
|
|
case prepare_search_term(string) do |
|
|
|
|
|
|
|
{:some, term} -> |
|
|
|
query = |
|
|
|
query = |
|
|
|
from(token in Token, |
|
|
|
from(token in Token, |
|
|
|
where: fragment("to_tsvector('english', symbol || ' ' || name ) @@ to_tsquery(?)", ^term_final), |
|
|
|
where: fragment("to_tsvector('english', symbol || ' ' || name ) @@ to_tsquery(?)", ^term), |
|
|
|
select: %{ |
|
|
|
select: %{ |
|
|
|
contract_address_hash: token.contract_address_hash, |
|
|
|
contract_address_hash: token.contract_address_hash, |
|
|
|
symbol: token.symbol, |
|
|
|
symbol: token.symbol, |
|
|
@ -1110,24 +1120,27 @@ defmodule Explorer.Chain do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
|
|
|
[] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec search_contract(String.t()) :: [SmartContract.t()] |
|
|
|
@spec search_contract(String.t()) :: [SmartContract.t()] |
|
|
|
def search_contract(word) do |
|
|
|
def search_contract(string) do |
|
|
|
term = |
|
|
|
case prepare_search_term(string) do |
|
|
|
word |
|
|
|
{:some, term} -> |
|
|
|
|> String.replace(~r/[^a-zA-Z0-9]/, " ") |
|
|
|
|
|
|
|
|> String.replace(~r/ +/, " & ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
term_final = term <> ":*" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query = |
|
|
|
query = |
|
|
|
from(smart_contract in SmartContract, |
|
|
|
from(smart_contract in SmartContract, |
|
|
|
where: fragment("to_tsvector('english', name ) @@ to_tsquery(?)", ^term_final), |
|
|
|
where: fragment("to_tsvector('english', name ) @@ to_tsquery(?)", ^term), |
|
|
|
select: %{contract_address_hash: smart_contract.address_hash, name: smart_contract.name} |
|
|
|
select: %{contract_address_hash: smart_contract.address_hash, name: smart_contract.name} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
|
|
|
[] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|