Use content instead of source and scrub it
authorEkaterina Vaartis <vaartis@kotobank.ch>
Mon, 16 Aug 2021 21:57:53 +0000 (00:57 +0300)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 29 Jun 2022 19:48:29 +0000 (20:48 +0100)
lib/mix/tasks/pleroma/search/meilisearch.ex
lib/pleroma/search/meilisearch.ex

index dcecbd7cfb8f65c2520571110bc28a62adf213ce..5270de25581a7dfbb2c8a379c6aacc55647dc21e 100644 (file)
@@ -37,7 +37,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
             # Only index public posts which are notes and have some text
             where:
               fragment("data->>'type' = 'Note'") and
-                fragment("LENGTH(data->>'source') > 0") and
+                fragment("LENGTH(data->>'content') > 0") and
                 fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
             order_by: [desc: fragment("data->'published'")]
           ),
@@ -56,10 +56,11 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
             data = object.data
 
             {:ok, published, _} = DateTime.from_iso8601(data["published"])
+            {:ok, content} = FastSanitize.strip_tags(data["content"])
 
             %{
               id: object.id,
-              source: data["source"],
+              content: content,
               ap: data["id"],
               published: published |> DateTime.to_unix()
             }
@@ -87,11 +88,6 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
 
     endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
 
-    {:ok, result} =
-      Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])
-
-    if not Map.has_key?(Jason.decode!(result.body), "updateId") do
-      IO.puts("Failed to clear: #{result}")
-    end
+    {:ok, _} = Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects", "", [], [])
   end
 end
index 9fdb0a07feb2bc95a7520bac63a11f85eb218386..87fdeaf5e0b30c54ba6f363a916e86557eef1692 100644 (file)
@@ -56,7 +56,7 @@ defmodule Pleroma.Search.Meilisearch do
           Jason.encode!([
             %{
               id: object.id,
-              source: data["source"],
+              content: data["content"] |> Pleroma.HTML.filter_tags(),
               ap: data["id"],
               published: published |> DateTime.to_unix()
             }