change for local user search
This commit is contained in:
parent
3a406db430
commit
23d4781e73
|
@ -150,7 +150,7 @@ defp boost_search_rank_query(query, for_user) do
|
||||||
@spec fts_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
@spec fts_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
||||||
defp fts_search_subquery(query, term) do
|
defp fts_search_subquery(query, term) do
|
||||||
processed_query =
|
processed_query =
|
||||||
term
|
String.trim_trailing(term, "@" <> local_domain())
|
||||||
|> String.replace(~r/\W+/, " ")
|
|> String.replace(~r/\W+/, " ")
|
||||||
|> String.trim()
|
|> String.trim()
|
||||||
|> String.split()
|
|> String.split()
|
||||||
|
@ -192,6 +192,8 @@ defp fts_search_subquery(query, term) do
|
||||||
|
|
||||||
@spec trigram_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
@spec trigram_search_subquery(User.t() | Ecto.Query.t(), String.t()) :: Ecto.Query.t()
|
||||||
defp trigram_search_subquery(query, term) do
|
defp trigram_search_subquery(query, term) do
|
||||||
|
term = String.trim_trailing(term, "@" <> local_domain())
|
||||||
|
|
||||||
from(
|
from(
|
||||||
u in query,
|
u in query,
|
||||||
select_merge: %{
|
select_merge: %{
|
||||||
|
@ -209,4 +211,6 @@ defp trigram_search_subquery(query, term) do
|
||||||
)
|
)
|
||||||
|> User.restrict_deactivated()
|
|> User.restrict_deactivated()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp local_domain, do: Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||||
end
|
end
|
||||||
|
|
|
@ -217,5 +217,36 @@ test "excludes a blocked users from search result" do
|
||||||
refute Enum.member?(account_ids, blocked_user2.id)
|
refute Enum.member?(account_ids, blocked_user2.id)
|
||||||
assert length(account_ids) == 3
|
assert length(account_ids) == 3
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue