Merge branch 'develop' of gitssh.ihatebeinga.live:IHBAGang/pleroma into develop
[akkoma] / lib / mix / tasks / pleroma / search.ex
index 9e0f376c38957a2c3042fb15b45196b9edabb07e..2324561c1baaed6736da3ab101e0adc72a3e732a 100644 (file)
@@ -8,20 +8,38 @@ defmodule Mix.Tasks.Pleroma.Search do
   import Ecto.Query
   alias Pleroma.Activity
   alias Pleroma.Pagination
+  alias Pleroma.User
+  alias Pleroma.Hashtag
 
   @shortdoc "Manages elasticsearch"
 
-  def run(["import" | _rest]) do
+  def run(["import", "activities" | _rest]) do
     start_pleroma()
 
     from(a in Activity, where: not ilike(a.actor, "%/relay"))
+    |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data))
     |> Activity.with_preloaded_object()
     |> Activity.with_preloaded_user_actor()
-    |> get_all
+    |> get_all(:activities)
   end
 
-  defp get_all(query, max_id \\ nil) do
-    params = %{limit: 20}
+  def run(["import", "users" | _rest]) do
+    start_pleroma()  
+                     
+    from(u in User, where: u.nickname not in ["internal.fetch", "relay"])
+    |> get_all(:users)
+  end
+
+  def run(["import", "hashtags" | _rest]) do
+    start_pleroma()
+
+    from(h in Hashtag)
+    |> Pleroma.Repo.all()
+    |> Pleroma.Elasticsearch.bulk_post(:hashtags)
+  end
+
+  defp get_all(query, index, max_id \\ nil) do
+    params = %{limit: 1000}
 
     params =
       if max_id == nil do
@@ -38,9 +56,9 @@ defmodule Mix.Tasks.Pleroma.Search do
       :ok
     else
       res
-      |> Pleroma.Elasticsearch.bulk_post(:activities)
+      |> Pleroma.Elasticsearch.bulk_post(index)
 
-      get_all(query, List.last(res).id)
+      get_all(query, index, List.last(res).id)
     end
   end
 end