forked from AkkomaGang/akkoma
Merge branch '1892-exclude-bots-from-search-results' into 'develop'
[#1892] Exclusion of service actors from user search results Closes #1892 See merge request pleroma/pleroma!2708
This commit is contained in:
commit
19fbfbb767
2 changed files with 15 additions and 1 deletions
|
@ -52,6 +52,7 @@ defp search_query(query_string, for_user, following) do
|
||||||
|> base_query(following)
|
|> base_query(following)
|
||||||
|> filter_blocked_user(for_user)
|
|> filter_blocked_user(for_user)
|
||||||
|> filter_invisible_users()
|
|> filter_invisible_users()
|
||||||
|
|> filter_internal_users()
|
||||||
|> filter_blocked_domains(for_user)
|
|> filter_blocked_domains(for_user)
|
||||||
|> fts_search(query_string)
|
|> fts_search(query_string)
|
||||||
|> trigram_rank(query_string)
|
|> trigram_rank(query_string)
|
||||||
|
@ -109,6 +110,10 @@ defp filter_invisible_users(query) do
|
||||||
from(q in query, where: q.invisible == false)
|
from(q in query, where: q.invisible == false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp filter_internal_users(query) do
|
||||||
|
from(q in query, where: q.actor_type != "Application")
|
||||||
|
end
|
||||||
|
|
||||||
defp filter_blocked_user(query, %User{} = blocker) do
|
defp filter_blocked_user(query, %User{} = blocker) do
|
||||||
query
|
query
|
||||||
|> join(:left, [u], b in Pleroma.UserRelationship,
|
|> join(:left, [u], b in Pleroma.UserRelationship,
|
||||||
|
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.UserSearchTest do
|
||||||
describe "User.search" do
|
describe "User.search" do
|
||||||
setup do: clear_config([:instance, :limit_to_local_content])
|
setup do: clear_config([:instance, :limit_to_local_content])
|
||||||
|
|
||||||
test "excluded invisible users from results" do
|
test "excludes invisible users from results" do
|
||||||
user = insert(:user, %{nickname: "john t1000"})
|
user = insert(:user, %{nickname: "john t1000"})
|
||||||
insert(:user, %{invisible: true, nickname: "john t800"})
|
insert(:user, %{invisible: true, nickname: "john t800"})
|
||||||
|
|
||||||
|
@ -25,6 +25,15 @@ test "excluded invisible users from results" do
|
||||||
assert found_user.id == user.id
|
assert found_user.id == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "excludes service actors from results" do
|
||||||
|
insert(:user, actor_type: "Application", nickname: "user1")
|
||||||
|
service = insert(:user, actor_type: "Service", nickname: "user2")
|
||||||
|
person = insert(:user, actor_type: "Person", nickname: "user3")
|
||||||
|
|
||||||
|
assert [found_user1, found_user2] = User.search("user")
|
||||||
|
assert [found_user1.id, found_user2.id] -- [service.id, person.id] == []
|
||||||
|
end
|
||||||
|
|
||||||
test "accepts limit parameter" do
|
test "accepts limit parameter" do
|
||||||
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
||||||
assert length(User.search("john", limit: 3)) == 3
|
assert length(User.search("john", limit: 3)) == 3
|
||||||
|
|
Loading…
Reference in a new issue