[#1043] fix search accounts.
This commit is contained in:
parent
497788a3cc
commit
6dadf5d6f4
5 changed files with 252 additions and 190 deletions
|
|
@ -43,6 +43,8 @@ defmodule Pleroma.User.Search do
|
|||
defp search_query(query_string, for_user, following) do
|
||||
for_user
|
||||
|> base_query(following)
|
||||
|> filter_blocked_user(for_user)
|
||||
|> filter_blocked_domains(for_user)
|
||||
|> search_subqueries(query_string)
|
||||
|> union_subqueries
|
||||
|> distinct_query()
|
||||
|
|
@ -55,6 +57,25 @@ defmodule Pleroma.User.Search do
|
|||
defp base_query(_user, false), do: User
|
||||
defp base_query(user, true), do: User.get_followers_query(user)
|
||||
|
||||
defp filter_blocked_user(query, %User{info: %{blocks: blocks}})
|
||||
when length(blocks) > 0 do
|
||||
from(q in query, where: not (q.ap_id in ^blocks))
|
||||
end
|
||||
|
||||
defp filter_blocked_user(query, _), do: query
|
||||
|
||||
defp filter_blocked_domains(query, %User{info: %{domain_blocks: domain_blocks}})
|
||||
when length(domain_blocks) > 0 do
|
||||
domains = Enum.join(domain_blocks, ",")
|
||||
|
||||
from(
|
||||
q in query,
|
||||
where: fragment("substring(ap_id from '.*://([^/]*)') NOT IN (?)", ^domains)
|
||||
)
|
||||
end
|
||||
|
||||
defp filter_blocked_domains(query, _), do: query
|
||||
|
||||
defp paginate(query, limit, offset) do
|
||||
from(q in query, limit: ^limit, offset: ^offset)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue