Merge pull request #7666 from blockscout/vb-search-labels

Search label query
pull/7671/head
Victor Baranov 1 year ago committed by GitHub
commit b57724cdb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 30
      apps/explorer/lib/explorer/chain.ex

@ -32,6 +32,7 @@
### Chore
- [#7666](https://github.com/blockscout/blockscout/pull/7666) - Search label query
- [#7644](https://github.com/blockscout/blockscout/pull/7644) - Publish docker images CI for prod/staging branches
- [#7594](https://github.com/blockscout/blockscout/pull/7594) - Stats service support in docker-compose config with new frontend
- [#7576](https://github.com/blockscout/blockscout/pull/7576) - Check left blocks in pending block operations in order to decide, if we need to display indexing int tx banner at the top

@ -98,6 +98,7 @@ defmodule Explorer.Chain do
alias Explorer.Market.MarketHistoryCache
alias Explorer.{PagingOptions, Repo}
alias Explorer.SmartContract.Helper
alias Explorer.Tags.{AddressTag, AddressToTag}
alias Dataloader.Ecto, as: DataloaderEcto
@ -1500,6 +1501,31 @@ defmodule Explorer.Chain do
end
end
def search_label_query(term) do
inner_query =
from(tag in AddressTag,
where: fragment("to_tsvector('english', display_name ) @@ to_tsquery(?)", ^term),
select: tag
)
from(att in AddressToTag,
inner_join: at in subquery(inner_query),
on: att.tag_id == at.id,
select: %{
address_hash: att.address_hash,
tx_hash: fragment("CAST(NULL AS bytea)"),
block_hash: fragment("CAST(NULL AS bytea)"),
type: "label",
name: at.display_name,
symbol: ^nil,
holder_count: ^nil,
inserted_at: att.inserted_at,
block_number: 0,
icon_url: nil
}
)
end
defp search_token_query(term) do
from(token in Token,
where: fragment("to_tsvector(symbol || ' ' || name ) @@ to_tsquery(?)", ^term),
@ -1646,6 +1672,7 @@ defmodule Explorer.Chain do
{:some, term} ->
tokens_query = search_token_query(term)
contracts_query = search_contract_query(term)
labels_query = search_label_query(term)
tx_query = search_tx_query(string)
address_query = search_address_query(string)
block_query = search_block_query(string)
@ -1653,7 +1680,8 @@ defmodule Explorer.Chain do
basic_query =
from(
tokens in subquery(tokens_query),
union: ^contracts_query
union: ^contracts_query,
union: ^labels_query
)
query =

Loading…
Cancel
Save