From 7e9f7ea0c21d51c5fedf89ea1feb503b77c78bba Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 6 Jun 2019 16:16:22 +0200 Subject: [PATCH 1/2] MastodonAPI: Add test for user search. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 51c1cdfac..33c8e209a 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -2185,6 +2185,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert account["acct"] == "shp@social.heldscal.la" 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 user = insert(:user) other_user = insert(:user) From cb2bcee842f07358db4d37de1b9a32c9d69d487c Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 6 Jun 2019 16:18:27 +0200 Subject: [PATCH 2/2] User Search: Boost friends more strongly. --- lib/pleroma/user/search.ex | 4 ++-- test/tasks/user_test.exs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex index e74143cd0..add6a0bbf 100644 --- a/lib/pleroma/user/search.ex +++ b/lib/pleroma/user/search.ex @@ -86,8 +86,8 @@ defmodule Pleroma.User.Search do search_rank: fragment( """ - CASE WHEN (?) THEN (?) * 1.3 - WHEN (?) THEN (?) * 1.2 + CASE WHEN (?) THEN 0.5 + (?) * 1.3 + WHEN (?) THEN 0.5 + (?) * 1.2 WHEN (?) THEN (?) * 1.1 ELSE (?) END """, diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs index 260ce0d95..6fd7c7113 100644 --- a/test/tasks/user_test.exs +++ b/test/tasks/user_test.exs @@ -366,4 +366,25 @@ defmodule Mix.Tasks.Pleroma.UserTest do refute user.info.confirmation_token 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