Add a reindex option
authorEkaterina Vaartis <vaartis@kotobank.ch>
Wed, 10 Nov 2021 18:25:12 +0000 (21:25 +0300)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 29 Jun 2022 19:48:44 +0000 (20:48 +0100)
Signed-off-by: Ekaterina Vaartis <vaartis@kotobank.ch>
lib/mix/tasks/pleroma/search/meilisearch.ex

index cdf9ab0bd3b408f62b897c9bd56a44bf6d262ff9..2a3c3a8b925383d1bf2ad2a3de9853c7407ec1a7 100644 (file)
@@ -11,9 +11,11 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
 
   import Pleroma.Search.Meilisearch, only: [meili_post!: 2, meili_delete!: 1, meili_get!: 1]
 
-  def run(["index"]) do
+  def run(["index" | args]) do
     start_pleroma()
 
+    is_reindex = "--reindex" in args
+
     meili_post!(
       "/indexes/objects/settings/ranking-rules",
       [
@@ -68,6 +70,19 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
           {[objects], new_acc}
         end)
         |> Stream.each(fn objects ->
+          objects =
+            objects
+            |> Enum.filter(fn o ->
+              if is_reindex do
+                result = meili_get!("/indexes/objects/documents/#{o.id}")
+
+                # Filter out the already indexed documents. This is true when the document does not exist
+                result["errorCode"] == "document_not_found"
+              else
+                true
+              end
+            end)
+
           result =
             meili_post!(
               "/indexes/objects/documents",