extra cool

This commit is contained in:
sadposter 2021-12-14 14:48:24 +00:00
parent 0d7bbee430
commit 8378c3a8bc
5 changed files with 39 additions and 31 deletions

View file

@ -24,8 +24,8 @@ defmodule Mix.Tasks.Pleroma.Search do
end end
def run(["import", "users" | _rest]) do def run(["import", "users" | _rest]) do
start_pleroma() start_pleroma()
from(u in User, where: u.nickname not in ["internal.fetch", "relay"]) from(u in User, where: u.nickname not in ["internal.fetch", "relay"])
|> get_all(:users) |> get_all(:users)
end end

View file

@ -46,26 +46,31 @@ defmodule Pleroma.Elasticsearch do
end end
def put(%Activity{} = activity) do def put(%Activity{} = activity) do
{:ok, _} = Elastix.Document.index( {:ok, _} =
url(), Elastix.Document.index(
"activities", url(),
"activity", "activities",
DocumentMappings.Activity.id(activity), "activity",
DocumentMappings.Activity.encode(activity) DocumentMappings.Activity.id(activity),
) DocumentMappings.Activity.encode(activity)
{:ok, _} = bulk_post( )
activity.object.hashtags, :hashtags
) {:ok, _} =
bulk_post(
activity.object.hashtags,
:hashtags
)
end end
def put(%User{} = user) do def put(%User{} = user) do
{:ok, _ } = Elastix.Document.index( {:ok, _} =
url(), Elastix.Document.index(
"users", url(),
"user", "users",
DocumentMappings.User.id(user), "user",
DocumentMappings.User.encode(user) DocumentMappings.User.id(user),
) DocumentMappings.User.encode(user)
)
end end
def bulk_post(data, :activities) do def bulk_post(data, :activities) do
@ -87,12 +92,13 @@ defmodule Pleroma.Elasticsearch do
end) end)
|> List.flatten() |> List.flatten()
{:ok, %{body: %{"errors" => false}}} = Elastix.Bulk.post( {:ok, %{body: %{"errors" => false}}} =
url(), Elastix.Bulk.post(
d, url(),
index: "activities", d,
type: "activity" index: "activities",
) type: "activity"
)
end end
def bulk_post(data, :users) do def bulk_post(data, :users) do
@ -115,7 +121,7 @@ defmodule Pleroma.Elasticsearch do
) )
end end
def bulk_post(data, :hashtags) do def bulk_post([] = data, :hashtags) do
d = d =
data data
|> Enum.map(fn d -> |> Enum.map(fn d ->
@ -134,6 +140,8 @@ defmodule Pleroma.Elasticsearch do
) )
end end
def bulk_post(_, :hashtags), do: {:ok, nil}
def search(:raw, index, type, q) do def search(:raw, index, type, q) do
with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do
results = results =

View file

@ -7,7 +7,7 @@ defmodule Pleroma.Search.Elasticsearch do
alias Pleroma.Search.Elasticsearch.Parsers alias Pleroma.Search.Elasticsearch.Parsers
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint
defp es_query(:activity, query) do def es_query(:activity, query) do
%{ %{
size: 50, size: 50,
terminate_after: 50, terminate_after: 50,
@ -23,7 +23,7 @@ defmodule Pleroma.Search.Elasticsearch do
} }
end end
defp es_query(:user, query) do def es_query(:user, query) do
%{ %{
size: 50, size: 50,
terminate_after: 50, terminate_after: 50,
@ -36,7 +36,7 @@ defmodule Pleroma.Search.Elasticsearch do
} }
end end
defp es_query(:hashtag, query) do def es_query(:hashtag, query) do
%{ %{
size: 50, size: 50,
terminate_after: 50, terminate_after: 50,

View file

@ -3,7 +3,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.Hashtag do
%{ %{
term: %{ term: %{
hashtag: %{ hashtag: %{
value: String.downcase(term), value: String.downcase(term)
} }
} }
} }

View file

@ -25,7 +25,7 @@ defmodule Pleroma.Search.Elasticsearch.Parsers.User do
query: term, query: term,
operator: "AND" operator: "AND"
} }
} }
} }
] ]
} }