mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-23 05:34:33 +01:00
* initial upgrade to elasticsearch 7 * fix stat page error * i am an idiot * fix es not creating new indexes * more complete removal of doc_type Co-authored-by: Luna D <cod7777@yandex.ru>
63 lines
1.6 KiB
Elixir
63 lines
1.6 KiB
Elixir
defmodule Philomena.Comments.ElasticsearchIndex do
|
|
@behaviour Philomena.ElasticsearchIndex
|
|
|
|
@impl true
|
|
def index_name do
|
|
"comments"
|
|
end
|
|
|
|
@impl true
|
|
def mapping do
|
|
%{
|
|
settings: %{
|
|
index: %{
|
|
number_of_shards: 5,
|
|
max_result_window: 10_000_000
|
|
}
|
|
},
|
|
mappings: %{
|
|
dynamic: false,
|
|
properties: %{
|
|
id: %{type: "integer"},
|
|
posted_at: %{type: "date"},
|
|
ip: %{type: "ip"},
|
|
fingerprint: %{type: "keyword"},
|
|
image_id: %{type: "keyword"},
|
|
user_id: %{type: "keyword"},
|
|
author: %{type: "keyword"},
|
|
image_tag_ids: %{type: "keyword"},
|
|
# boolean
|
|
anonymous: %{type: "keyword"},
|
|
# boolean
|
|
hidden_from_users: %{type: "keyword"},
|
|
body: %{type: "text", analyzer: "snowball"}
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
@impl true
|
|
def as_json(comment) do
|
|
%{
|
|
id: comment.id,
|
|
posted_at: comment.created_at,
|
|
ip: comment.ip |> to_string,
|
|
fingerprint: comment.fingerprint,
|
|
image_id: comment.image_id,
|
|
user_id: comment.user_id,
|
|
author: if(!!comment.user and !comment.anonymous, do: comment.user.name),
|
|
image_tag_ids: comment.image.tags |> Enum.map(& &1.id),
|
|
anonymous: comment.anonymous,
|
|
hidden_from_users: comment.image.hidden_from_users || comment.hidden_from_users,
|
|
body: comment.body
|
|
}
|
|
end
|
|
|
|
def user_name_update_by_query(old_name, new_name) do
|
|
%{
|
|
query: %{term: %{author: old_name}},
|
|
replacements: [%{path: ["author"], old: old_name, new: new_name}],
|
|
set_replacements: []
|
|
}
|
|
end
|
|
end
|