From: sadposter Date: Tue, 14 Dec 2021 14:48:24 +0000 (+0000) Subject: extra cool X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=8378c3a8bcd1104a9329091f47a00e41e70a7a00;p=akkoma extra cool --- diff --git a/lib/mix/tasks/pleroma/search.ex b/lib/mix/tasks/pleroma/search.ex index 2324561c1..1fd880eab 100644 --- a/lib/mix/tasks/pleroma/search.ex +++ b/lib/mix/tasks/pleroma/search.ex @@ -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 diff --git a/lib/pleroma/elasticsearch/store.ex b/lib/pleroma/elasticsearch/store.ex index 1d63e8816..f8d9090d7 100644 --- a/lib/pleroma/elasticsearch/store.ex +++ b/lib/pleroma/elasticsearch/store.ex @@ -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 = diff --git a/lib/pleroma/search/elasticsearch.ex b/lib/pleroma/search/elasticsearch.ex index 00ae6b3dc..145bdec7b 100644 --- a/lib/pleroma/search/elasticsearch.ex +++ b/lib/pleroma/search/elasticsearch.ex @@ -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, diff --git a/lib/pleroma/search/elasticsearch/hashtag_parser.ex b/lib/pleroma/search/elasticsearch/hashtag_parser.ex index 6e2801ed0..644969c78 100644 --- a/lib/pleroma/search/elasticsearch/hashtag_parser.ex +++ b/lib/pleroma/search/elasticsearch/hashtag_parser.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.Hashtag do %{ term: %{ hashtag: %{ - value: String.downcase(term), + value: String.downcase(term) } } } diff --git a/lib/pleroma/search/elasticsearch/user_paser.ex b/lib/pleroma/search/elasticsearch/user_paser.ex index 96bfdc7d2..76da3bd33 100644 --- a/lib/pleroma/search/elasticsearch/user_paser.ex +++ b/lib/pleroma/search/elasticsearch/user_paser.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.User do query: term, operator: "AND" } - } + } } ] }