Merge branch 'fix-search' into 'develop'

Fix search

Closes #960

See merge request pleroma/pleroma!1253
This commit is contained in:
rinpatch 2019-06-06 14:26:19 +00:00
commit 5f1b6f5aca
3 changed files with 32 additions and 2 deletions

View File

@ -86,8 +86,8 @@ defp boost_search_rank_query(query, for_user) do
search_rank: search_rank:
fragment( fragment(
""" """
CASE WHEN (?) THEN (?) * 1.3 CASE WHEN (?) THEN 0.5 + (?) * 1.3
WHEN (?) THEN (?) * 1.2 WHEN (?) THEN 0.5 + (?) * 1.2
WHEN (?) THEN (?) * 1.1 WHEN (?) THEN (?) * 1.1
ELSE (?) END ELSE (?) END
""", """,

View File

@ -366,4 +366,25 @@ test "user is not confirmed" do
refute user.info.confirmation_token refute user.info.confirmation_token
end end
end end
describe "search" do
test "it returns users matching" do
user = insert(:user)
moon = insert(:user, nickname: "moon", name: "fediverse expert moon")
moot = insert(:user, nickname: "moot")
kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
{:ok, user} = User.follow(user, kawen)
assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
res = User.search("moo") |> Enum.map(& &1.id)
assert moon.id in res
assert moot.id in res
assert kawen.id in res
assert [moon.id, kawen.id] == User.Search.search("moon fediverse") |> Enum.map(& &1.id)
assert [kawen.id, moon.id] ==
User.Search.search("moon fediverse", for_user: user) |> Enum.map(& &1.id)
end
end
end end

View File

@ -2185,6 +2185,15 @@ test "search fetches remote accounts", %{conn: conn} do
assert account["acct"] == "shp@social.heldscal.la" assert account["acct"] == "shp@social.heldscal.la"
end end
test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
conn =
conn
|> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "false"})
assert results = json_response(conn, 200)
assert [] == results["accounts"]
end
test "returns the favorites of a user", %{conn: conn} do test "returns the favorites of a user", %{conn: conn} do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)