only return create objects for ES search (#165)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 16 Aug 2022 23:24:19 +0000 (23:24 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 16 Aug 2022 23:24:19 +0000 (23:24 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/165

CHANGELOG.md
lib/pleroma/search/elasticsearch.ex
lib/pleroma/search/elasticsearch/store.ex

index 3618211e4648dbd67a5a59683416275a9adae57f..c1e1d01c41da9adc3035319acd363b8a978f8f8f 100644 (file)
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 ### Fixed
 - Compatibility with latest meilisearch
 - Resolution of nested mix tasks (i.e search.meilisearch) in OTP releases
+- Elasticsearch returning likes and repeats, displaying as posts
 
 ### Removed
 - Non-finch HTTP adapters. `:tesla, :adapter` is now highly recommended to be set to the default.
index 7c7ca82c8825e19a39b5807ec51afe9cb3d5b5e5..16b01101acced74ffb55d96f652aaa5b5e2fe6f3 100644 (file)
@@ -23,7 +23,7 @@ defmodule Pleroma.Search.Elasticsearch do
         timeout: "5s",
         sort: [
           "_score",
-          %{_timestamp: %{order: "desc", format: "basic_date_time"}}
+          %{"_timestamp" => %{order: "desc", format: "basic_date_time"}}
         ],
         query: %{
           bool: %{
@@ -62,8 +62,12 @@ defmodule Pleroma.Search.Elasticsearch do
       Task.async(fn ->
         q = es_query(:activity, parsed_query, offset, limit)
 
-        Pleroma.Search.Elasticsearch.Store.search(:activities, q)
-        |> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end)
+        :activities
+        |> Pleroma.Search.Elasticsearch.Store.search(q)
+        |> Enum.filter(fn x ->
+          x.data["type"] == "Create" && x.object.data["type"] == "Note" &&
+            Visibility.visible_for_user?(x, user)
+        end)
       end)
 
     activity_results = Task.await(activity_task)
index 895b76d7f85e12f9af6acbf47d07d4c24c524b78..3b7bbb838eff61df076af22178abb7df12b84d7c 100644 (file)
@@ -42,7 +42,6 @@ defmodule Pleroma.Search.Elasticsearch.Store do
       results
       |> Enum.map(fn result -> result["_id"] end)
       |> Pleroma.Activity.all_by_ids_with_object()
-      |> Enum.sort(&(&1.inserted_at >= &2.inserted_at))
     else
       e ->
         Logger.error(e)