Find by contract name

pull/3058/head
Victor Baranov 5 years ago
parent d7ed17f803
commit d4798b7223
  1. 13
      apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex
  2. 13
      apps/explorer/lib/explorer/chain.ex

@ -58,12 +58,21 @@ defmodule BlockScoutWeb.ChainController do
if term == "" do
json(conn, "{}")
else
result =
result_tokens =
term
|> String.trim()
|> Chain.search_token()
json(conn, result)
if result_tokens do
json(conn, result_tokens)
else
result_contracts =
term
|> String.trim()
|> Chain.search_contract()
json(conn, result_contracts)
end
end
end

@ -850,6 +850,19 @@ defmodule Explorer.Chain do
Repo.all(query)
end
@spec search_contract(String.t()) :: [SmartContract.t()]
def search_contract(word) do
term = String.replace(word, ~r/\W/u, "") <> ":*"
query =
from(token in SmartContract,
where: fragment("to_tsvector('english', name ) @@ to_tsquery(?)", ^term),
limit: 5
)
Repo.all(query)
end
@doc """
Converts `t:Explorer.Chain.Address.t/0` `hash` to the `t:Explorer.Chain.Address.t/0` with that `hash`.

Loading…
Cancel
Save