   def username_search(%{current_user: current_user} = opts) do
     following_ids = Network.following_ids(current_user)
     base_query()
-    |> build_username_query(opts)
+    |> build_user_query(opts)
     |> build_relationship_query(following_ids)
     |> filter_blocked(current_user)
     |> search_user_index

                     fields: ["name", "username"],
                     analyzer: "standard",
                     minimum_should_match: "100%"}} | &1]))
  end

  defp build_username_query(query, %{terms: username} = opts) do
    filtered_username = filter_terms(username, opts[:allow_nsfw])
    boost             = Application.get_env(:ello_search, :username_match_boost)

    query
    |> update_in([:query, :bool, :must], &([%{fuzzy: %{username: filtered_username}} | &1]))
    |> update_in([:query, :bool, :should], &([%{term: %{username: %{value: filtered_username, boost: boost}}} | &1]))
  end

  defp build_relationship_query(query, []), do: query

    |> update_in([:size], &(&1 = per_page))
  end

  defp build_user_query(query, %{terms: "@" <> terms} = opts), do: build_user_query(query, Map.merge(opts, %{terms: terms}))
  defp build_user_query(query, %{terms: terms} = opts) do
    filtered_terms = filter_terms(terms, opts[:allow_nsfw])
    update_in(query[:query][:bool][:must],
