projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'origin/feature/elasticsearch' into develop
[akkoma]
/
lib
/
pleroma
/
elasticsearch
/
store.ex
diff --git
a/lib/pleroma/elasticsearch/store.ex
b/lib/pleroma/elasticsearch/store.ex
index 2f8375c48fb4f0e2b40c2cc7faee66287bc14653..7f6ef37a927ad46dcbbbe4e36761c5b66e1b0e54 100644
(file)
--- a/
lib/pleroma/elasticsearch/store.ex
+++ b/
lib/pleroma/elasticsearch/store.ex
@@
-1,6
+1,7
@@
defmodule Pleroma.Elasticsearch do
alias Pleroma.Activity
alias Pleroma.User
defmodule Pleroma.Elasticsearch do
alias Pleroma.Activity
alias Pleroma.User
+ alias Pleroma.Object
alias Pleroma.Elasticsearch.DocumentMappings
alias Pleroma.Config
require Logger
alias Pleroma.Elasticsearch.DocumentMappings
alias Pleroma.Config
require Logger
@@
-35,7
+36,7
@@
defmodule Pleroma.Elasticsearch do
end
end
end
end
- def maybe_put_into_elasticsearch(%User{} = user) do
+ def maybe_put_into_elasticsearch(%User{
actor_type: "Person"
} = user) do
if enabled?() do
put(user)
end
if enabled?() do
put(user)
end
@@
-45,6
+46,12
@@
defmodule Pleroma.Elasticsearch do
{:ok, :skipped}
end
{:ok, :skipped}
end
+ def maybe_bulk_post(data, type) do
+ if enabled?() do
+ bulk_post(data, type)
+ end
+ end
+
def put(%Activity{} = activity) do
{:ok, _} =
Elastix.Document.index(
def put(%Activity{} = activity) do
{:ok, _} =
Elastix.Document.index(
@@
-55,11
+62,11
@@
defmodule Pleroma.Elasticsearch do
DocumentMappings.Activity.encode(activity)
)
DocumentMappings.Activity.encode(activity)
)
- {:ok, _} =
- bulk_post(
- activity.object.hashtags,
- :hashtags
-
)
+ activity
+ |> Map.get(:object)
+ |> Object.hashtags()
+ |> Enum.map(fn x -> %{id: x, name: x, timestamp: DateTime.to_iso8601(DateTime.utc_now())} end)
+
|> bulk_post(:hashtags
)
end
def put(%User{} = user) do
end
def put(%User{} = user) do
@@
-101,9
+108,11
@@
defmodule Pleroma.Elasticsearch do
)
end
)
end
+
def bulk_post(data, :users) do
d =
data
def bulk_post(data, :users) do
d =
data
+ |> Enum.filter(fn x -> x.actor_type == "Person" end)
|> Enum.map(fn d ->
[
%{index: %{_id: DocumentMappings.User.id(d)}},
|> Enum.map(fn d ->
[
%{index: %{_id: DocumentMappings.User.id(d)}},
@@
-120,7
+129,7
@@
defmodule Pleroma.Elasticsearch do
)
end
)
end
- def bulk_post(data, :hashtags) do
+ def bulk_post(data, :hashtags)
when is_list(data)
do
d =
data
|> Enum.map(fn d ->
d =
data
|> Enum.map(fn d ->
@@
-139,6
+148,10
@@
defmodule Pleroma.Elasticsearch do
)
end
)
end
+ def bulk_post(_, :hashtags), do: {:ok, nil}
+
+ def search(_, _, _, :skip), do: []
+
def search(:raw, index, type, q) do
with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do
results =
def search(:raw, index, type, q) do
with {:ok, raw_results} <- Elastix.Search.search(url(), index, [type], q) do
results =
@@
-160,6
+173,7
@@
defmodule Pleroma.Elasticsearch do
results
|> Enum.map(fn result -> result["_id"] end)
|> Pleroma.Activity.all_by_ids_with_object()
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)
else
e ->
Logger.error(e)