Add federated blocks
[akkoma] / lib / pleroma / user.ex
index e9196ae0391b8b254008d1414b567e2da2265c38..399a66787dff4bf01128bd6a9492c5242aafb656 100644 (file)
@@ -21,6 +21,7 @@ defmodule Pleroma.User do
     field(:local, :boolean, default: true)
     field(:info, :map, default: %{})
     field(:follower_address, :string)
+    field(:search_distance, :float, virtual: true)
     has_many(:notifications, Notification)
 
     timestamps()
@@ -104,7 +105,7 @@ defmodule Pleroma.User do
     |> cast(params, [:bio, :name])
     |> unique_constraint(:nickname)
     |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
-    |> validate_length(:bio, max: 1000)
+    |> validate_length(:bio, max: 5000)
     |> validate_length(:name, min: 1, max: 100)
   end
 
@@ -399,19 +400,23 @@ defmodule Pleroma.User do
       User.get_or_fetch_by_nickname(query)
     end
 
-    q =
+    inner =
       from(
         u in User,
-        where:
-          fragment(
-            "(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)",
+        select_merge: %{
+          search_distance: fragment(
+            "? <-> (? || ?)",
+            ^query,
             u.nickname,
-            u.name,
-            ^query
-          ),
-        limit: 20
+            u.name
+          )}
       )
 
+    q = from(s in subquery(inner),
+      order_by: s.search_distance,
+      limit: 20
+    )
+
     Repo.all(q)
   end