1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.Search do
13 def user(%{query: term} = params) when is_nil(term) or term == "" do
14 query = maybe_filtered_query(params)
17 maybe_filtered_query(params)
18 |> paginate(params[:page] || 1, params[:page_size] || @page_size)
20 count = query |> Repo.aggregate(:count, :id)
22 results = Repo.all(paginated_query)
27 def user(%{query: term} = params) when is_binary(term) do
28 search_query = from(u in maybe_filtered_query(params), where: ilike(u.nickname, ^"%#{term}%"))
30 count = search_query |> Repo.aggregate(:count, :id)
34 |> paginate(params[:page] || 1, params[:page_size] || @page_size)
40 defp maybe_filtered_query(params) do
41 from(u in User, order_by: u.nickname)
42 |> User.maybe_local_user_query(params[:local])
43 |> User.maybe_external_user_query(params[:external])
44 |> User.maybe_active_user_query(params[:active])
45 |> User.maybe_deactivated_user_query(params[:deactivated])
48 defp paginate(query, page, page_size) do
51 offset: ^((page - 1) * page_size)