mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Merge branch 'fix/966-local-user-search' into 'develop'
change for local user search Closes #966 See merge request pleroma/pleroma!1287
This commit is contained in:
commit
8574ebfc12
2 changed files with 36 additions and 1 deletions
|
@ -150,7 +150,7 @@ defmodule Pleroma.User.Search do
|
|||
@spec fts_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
||||
defp fts_search_subquery(query, term) do
|
||||
processed_query =
|
||||
term
|
||||
String.trim_trailing(term, "@" <> local_domain())
|
||||
|> String.replace(~r/\W+/, " ")
|
||||
|> String.trim()
|
||||
|> String.split()
|
||||
|
@ -192,6 +192,8 @@ defmodule Pleroma.User.Search do
|
|||
|
||||
@spec trigram_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
||||
defp trigram_search_subquery(query, term) do
|
||||
term = String.trim_trailing(term, "@" <> local_domain())
|
||||
|
||||
from(
|
||||
u in query,
|
||||
select_merge: %{
|
||||
|
@ -209,4 +211,6 @@ defmodule Pleroma.User.Search do
|
|||
)
|
||||
|> User.restrict_deactivated()
|
||||
end
|
||||
|
||||
defp local_domain, do: Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||
end
|
||||
|
|
|
@ -217,5 +217,36 @@ defmodule Pleroma.UserSearchTest do
|
|||
refute Enum.member?(account_ids, blocked_user2.id)
|
||||
assert length(account_ids) == 3
|
||||
end
|
||||
|
||||
test "local user has the same search_rank as for users with the same nickname, but another domain" do
|
||||
user = insert(:user)
|
||||
insert(:user, nickname: "lain@mastodon.social")
|
||||
insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "lain@pleroma.social")
|
||||
|
||||
assert User.search("lain@localhost", resolve: true, for_user: user)
|
||||
|> Enum.each(fn u -> u.search_rank == 0.5 end)
|
||||
end
|
||||
|
||||
test "localhost is the part of the domain" do
|
||||
user = insert(:user)
|
||||
insert(:user, nickname: "another@somedomain")
|
||||
insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "lain@examplelocalhost")
|
||||
|
||||
result = User.search("lain@examplelocalhost", resolve: true, for_user: user)
|
||||
assert Enum.each(result, fn u -> u.search_rank == 0.5 end)
|
||||
assert length(result) == 2
|
||||
end
|
||||
|
||||
test "local user search with users" do
|
||||
user = insert(:user)
|
||||
local_user = insert(:user, nickname: "lain")
|
||||
insert(:user, nickname: "another@localhost.com")
|
||||
insert(:user, nickname: "localhost@localhost.com")
|
||||
|
||||
[result] = User.search("lain@localhost", resolve: true, for_user: user)
|
||||
assert Map.put(result, :search_rank, nil) |> Map.put(:search_type, nil) == local_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue