User Search: Remove superfluous setweight and random test.
authorlain <lain@soykaf.club>
Mon, 4 Nov 2019 15:57:41 +0000 (16:57 +0100)
committerlain <lain@soykaf.club>
Mon, 4 Nov 2019 15:57:41 +0000 (16:57 +0100)
The test tested for a behavior that isn't actually enforced anymore.

lib/pleroma/user/search.ex
test/user_search_test.exs

index bab8d92e2be299f78101a209219fdb7d4f6a31ab..09664db76b7393a144c9d54972ba3a884eabb7bf 100644 (file)
@@ -54,15 +54,7 @@ defmodule Pleroma.User.Search do
     |> maybe_restrict_local(for_user)
   end
 
-  @nickname_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~\-@]+$/
   defp fts_search(query, query_string) do
-    {nickname_weight, name_weight} =
-      if String.match?(query_string, @nickname_regex) do
-        {"A", "B"}
-      else
-        {"B", "A"}
-      end
-
     query_string = to_tsquery(query_string)
 
     from(
@@ -70,12 +62,10 @@ defmodule Pleroma.User.Search do
       where:
         fragment(
           """
-          (setweight(to_tsvector('simple', ?), ?) || setweight(to_tsvector('simple', ?), ?)) @@ to_tsquery('simple', ?)
+          (to_tsvector('simple', ?) || to_tsvector('simple', ?)) @@ to_tsquery('simple', ?)
           """,
           u.name,
-          ^name_weight,
           u.nickname,
-          ^nickname_weight,
           ^query_string
         )
     )
index 78a02d5364c5434fc2dda5f3c83f5caa96512daf..721af1e5bb9bbecc1d677f3309dceb8126d1d1dd 100644 (file)
@@ -51,13 +51,6 @@ defmodule Pleroma.UserSearchTest do
       end)
     end
 
-    test "finds users, preferring nickname matches over name matches" do
-      u1 = insert(:user, %{name: "lain", nickname: "nick1"})
-      u2 = insert(:user, %{nickname: "lain", name: "nick1"})
-
-      assert [u2.id, u1.id] == Enum.map(User.search("lain"), & &1.id)
-    end
-
     test "finds users, considering density of matched tokens" do
       u1 = insert(:user, %{name: "Bar Bar plus Word Word"})
       u2 = insert(:user, %{name: "Word Word Bar Bar Bar"})