Improve search: allow search with space

pull/3231/head
Victor Baranov 4 years ago
parent 37f8120041
commit 9e75193257
  1. 2
      CHANGELOG.md
  2. 4
      apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex
  3. 6
      apps/block_scout_web/priv/gettext/default.pot
  4. 6
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  5. 25
      apps/explorer/lib/explorer/chain.ex

@ -5,6 +5,8 @@
- [#3224](https://github.com/poanetwork/blockscout/pull/3224) - Top tokens page
### Fixes
- [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: allow search with space
- [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: order by token holders in descendant order
- [#3226](https://github.com/poanetwork/blockscout/pull/3226) - Fix notifier query for live update of token transfers
- [#3220](https://github.com/poanetwork/blockscout/pull/3220) - Allow interaction with navbar menu at block-not-found page

@ -167,7 +167,7 @@
<%= awesomplete(f, :q,
[
class: "form-control me auto",
placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"),
placeholder: gettext("Search by address, token symbol, name, transaction hash, or block number"),
"aria-describedby": "search-icon",
"aria-label": gettext("Search"),
"data-test": "search_input"
@ -178,7 +178,7 @@
value: "contract_address_hash",
label: "contract_address_hash",
descrSearch: true,
descr: "symbol"
descr: "name"
]) %>
<div class="input-group-append">
<button class="input-group-text" id="search-icon">

@ -1250,7 +1250,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:166
#: lib/block_scout_web/templates/layout/_topnav.html.eex:170
msgid "Search by address, token symbol name, transaction hash, or block number"
msgstr ""
@ -1940,3 +1939,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:15
msgid "Copy Raw Trace"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:170
msgid "Search by address, token symbol, name, transaction hash, or block number"
msgstr ""

@ -1250,7 +1250,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:166
#: lib/block_scout_web/templates/layout/_topnav.html.eex:170
msgid "Search by address, token symbol name, transaction hash, or block number"
msgstr ""
@ -1940,3 +1939,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:15
msgid "Copy Raw Trace"
msgstr ""
#, elixir-format, fuzzy
#: lib/block_scout_web/templates/layout/_topnav.html.eex:170
msgid "Search by address, token symbol, name, transaction hash, or block number"
msgstr ""

@ -1034,13 +1034,22 @@ defmodule Explorer.Chain do
@spec search_token(String.t()) :: [Token.t()]
def search_token(word) do
term = String.replace(word, ~r/\W/u, "") <> ":*"
term =
word
|> String.replace(~r/ +/, " & ")
term_final = term <> ":*"
query =
from(token in Token,
where: fragment("to_tsvector('english', symbol || ' ' || name ) @@ to_tsquery(?)", ^term),
where: fragment("to_tsvector('english', symbol || ' ' || name ) @@ to_tsquery(?)", ^term_final),
limit: 5,
select: %{contract_address_hash: token.contract_address_hash, symbol: token.symbol, name: token.name}
select: %{
contract_address_hash: token.contract_address_hash,
symbol: token.symbol,
name: fragment("coalesce(?, '') || ' (' || coalesce(?, '') || ')'", token.name, token.symbol)
},
order_by: [desc: token.holder_count]
)
Repo.all(query)
@ -1048,13 +1057,17 @@ defmodule Explorer.Chain do
@spec search_contract(String.t()) :: [SmartContract.t()]
def search_contract(word) do
term = String.replace(word, ~r/\W/u, "") <> ":*"
term =
word
|> String.replace(~r/ +/, " & ")
term_final = term <> ":*"
query =
from(smart_contract in SmartContract,
where: fragment("to_tsvector('english', name ) @@ to_tsquery(?)", ^term),
where: fragment("to_tsvector('english', name ) @@ to_tsquery(?)", ^term_final),
limit: 5,
select: %{contract_address_hash: smart_contract.address_hash, symbol: smart_contract.name}
select: %{contract_address_hash: smart_contract.address_hash, name: smart_contract.name}
)
Repo.all(query)

Loading…
Cancel
Save