|
|
|
@ -8,6 +8,16 @@ defmodule BlockScoutWeb.API.V2.SearchController do |
|
|
|
|
alias Explorer.PagingOptions |
|
|
|
|
|
|
|
|
|
@api_true [api?: true] |
|
|
|
|
@min_query_length 3 |
|
|
|
|
|
|
|
|
|
def search(conn, %{"q" => query}) when byte_size(query) < @min_query_length do |
|
|
|
|
conn |
|
|
|
|
|> put_status(200) |
|
|
|
|
|> render(:search_results, %{ |
|
|
|
|
search_results: [], |
|
|
|
|
next_page_params: nil |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def search(conn, %{"q" => query} = params) do |
|
|
|
|
[paging_options: paging_options] = paging_options(params) |
|
|
|
@ -29,6 +39,12 @@ defmodule BlockScoutWeb.API.V2.SearchController do |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def check_redirect(conn, %{"q" => query}) when byte_size(query) < @min_query_length do |
|
|
|
|
conn |
|
|
|
|
|> put_status(200) |
|
|
|
|
|> render(:search_results, %{result: {:error, :not_found}}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def check_redirect(conn, %{"q" => query}) do |
|
|
|
|
result = |
|
|
|
|
query |
|
|
|
@ -40,6 +56,12 @@ defmodule BlockScoutWeb.API.V2.SearchController do |
|
|
|
|
|> render(:search_results, %{result: result}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def quick_search(conn, %{"q" => query}) when byte_size(query) < @min_query_length do |
|
|
|
|
conn |
|
|
|
|
|> put_status(200) |
|
|
|
|
|> render(:search_results, %{search_results: []}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def quick_search(conn, %{"q" => query}) do |
|
|
|
|
search_results = Search.balanced_unpaginated_search(%PagingOptions{page_size: 50}, query, @api_true) |
|
|
|
|
|
|
|
|
|