alias Pleroma.Activity
alias Pleroma.Pagination
alias Pleroma.User
+ alias Pleroma.Hashtag
@shortdoc "Manages elasticsearch"
|> get_all(:users)
end
+ def run(["import", "hashtags" | _rest]) do
+ start_pleroma()
+
+ from(h in Hashtag)
+ |> Pleroma.Repo.all()
+ |> Pleroma.Elasticsearch.bulk_post(:hashtags)
+ end
+
defp get_all(query, index, max_id \\ nil) do
- params = %{limit: 2000}
+ params = %{limit: 1000}
params =
if max_id == nil do
--- /dev/null
+defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do
+ def id(obj), do: obj.id
+
+ def encode(hashtag) do
+ %{
+ hashtag: hashtag.name,
+ timestamp: hashtag.inserted_at
+ }
+ end
+end
)
end
+ def bulk_post(data, :hashtags) do
+ d =
+ data
+ |> Enum.map(fn d ->
+ [
+ %{index: %{_id: DocumentMappings.Hashtag.id(d)}},
+ DocumentMappings.Hashtag.encode(d)
+ ]
+ end)
+ |> List.flatten()
+
+ Elastix.Bulk.post(
+ url(),
+ d,
+ index: "hashtags",
+ type: "hashtag"
+ )
+ end
+
def search_activities(q) do
Elastix.Search.search(
url(),