extra cool
authorsadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 14 Dec 2021 14:48:24 +0000 (14:48 +0000)
committersadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 14 Dec 2021 14:48:24 +0000 (14:48 +0000)
lib/mix/tasks/pleroma/search.ex
lib/pleroma/elasticsearch/store.ex
lib/pleroma/search/elasticsearch.ex
lib/pleroma/search/elasticsearch/hashtag_parser.ex
lib/pleroma/search/elasticsearch/user_paser.ex

index 2324561c1baaed6736da3ab101e0adc72a3e732a..1fd880eab61fe9a4037c59432494fe702e29a865 100644 (file)
@@ -24,8 +24,8 @@ defmodule Mix.Tasks.Pleroma.Search do
   end
 
   def run(["import", "users" | _rest]) do
-    start_pleroma()  
-                     
+    start_pleroma()
+
     from(u in User, where: u.nickname not in ["internal.fetch", "relay"])
     |> get_all(:users)
   end
index 1d63e88169e3908838e498bd34ba8945cde33c25..f8d9090d7f570a3db28b3bb057f48baeaf6c3d50 100644 (file)
@@ -46,26 +46,31 @@ defmodule Pleroma.Elasticsearch do
   end
 
   def put(%Activity{} = activity) do
-    {:ok, _} = Elastix.Document.index(
-      url(),
-      "activities",
-      "activity",
-      DocumentMappings.Activity.id(activity),
-      DocumentMappings.Activity.encode(activity)
-    )
-    {:ok, _} = bulk_post(
-        activity.object.hashtags, :hashtags
-    )
+    {:ok, _} =
+      Elastix.Document.index(
+        url(),
+        "activities",
+        "activity",
+        DocumentMappings.Activity.id(activity),
+        DocumentMappings.Activity.encode(activity)
+      )
+
+    {:ok, _} =
+      bulk_post(
+        activity.object.hashtags,
+        :hashtags
+      )
   end
 
   def put(%User{} = user) do
-    {:ok, _ } = Elastix.Document.index(
-      url(),
-      "users",
-      "user",
-      DocumentMappings.User.id(user),
-      DocumentMappings.User.encode(user)
-    )
+    {:ok, _} =
+      Elastix.Document.index(
+        url(),
+        "users",
+        "user",
+        DocumentMappings.User.id(user),
+        DocumentMappings.User.encode(user)
+      )
   end
 
   def bulk_post(data, :activities) do
@@ -87,12 +92,13 @@ defmodule Pleroma.Elasticsearch do
       end)
       |> List.flatten()
 
-    {:ok, %{body: %{"errors" => false}}} = Elastix.Bulk.post(
-      url(),
-      d,
-      index: "activities",
-      type: "activity"
-    )
+    {:ok, %{body: %{"errors" => false}}} =
+      Elastix.Bulk.post(
+        url(),
+        d,
+        index: "activities",
+        type: "activity"
+      )
   end
 
   def bulk_post(data, :users) do
@@ -115,7 +121,7 @@ defmodule Pleroma.Elasticsearch do
     )
   end
 
-  def bulk_post(data, :hashtags) do
+  def bulk_post([] = data, :hashtags) do
     d =
       data
       |> Enum.map(fn d ->
@@ -134,6 +140,8 @@ defmodule Pleroma.Elasticsearch do
     )
   end
 
+  def bulk_post(_, :hashtags), do: {:ok, nil}
+
   def search(:raw, index, type, q) do
     with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do
       results =
index 00ae6b3dccacd4fc19b846f83092b9e426c4e307..145bdec7b6c33824a34869fc10c4159ad11a104e 100644 (file)
@@ -7,7 +7,7 @@ defmodule Pleroma.Search.Elasticsearch do
   alias Pleroma.Search.Elasticsearch.Parsers
   alias Pleroma.Web.Endpoint
 
-  defp es_query(:activity, query) do
+  def es_query(:activity, query) do
     %{
       size: 50,
       terminate_after: 50,
@@ -23,7 +23,7 @@ defmodule Pleroma.Search.Elasticsearch do
     }
   end
 
-  defp es_query(:user, query) do
+  def es_query(:user, query) do
     %{
       size: 50,
       terminate_after: 50,
@@ -36,7 +36,7 @@ defmodule Pleroma.Search.Elasticsearch do
     }
   end
 
-  defp es_query(:hashtag, query) do
+  def es_query(:hashtag, query) do
     %{
       size: 50,
       terminate_after: 50,
index 6e2801ed07aea0428d34e160425f5046ab484628..644969c786394722cc6c9db413af0e969ee20f76 100644 (file)
@@ -3,7 +3,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.Hashtag do
     %{
       term: %{
         hashtag: %{
-          value: String.downcase(term),
+          value: String.downcase(term)
         }
       }
     }
index 96bfdc7d259f4a3745d28f4b181c99f2dd39b5f3..76da3bd3330e366af54d71443c5ac4d3d278dc63 100644 (file)
@@ -25,7 +25,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.User do
                 query: term,
                 operator: "AND"
               }
-            }  
+            }
           }
         ]
       }