add hashtag indexing

This commit is contained in:
FloatingGhost 2021-12-14 12:37:10 +00:00
parent 6ca70833f5
commit a85bf5929b
4 changed files with 43 additions and 1 deletions

View file

@ -9,6 +9,7 @@ defmodule Mix.Tasks.Pleroma.Search do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Pagination alias Pleroma.Pagination
alias Pleroma.User alias Pleroma.User
alias Pleroma.Hashtag
@shortdoc "Manages elasticsearch" @shortdoc "Manages elasticsearch"
@ -29,8 +30,16 @@ defmodule Mix.Tasks.Pleroma.Search do
|> get_all(:users) |> get_all(:users)
end 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 defp get_all(query, index, max_id \\ nil) do
params = %{limit: 2000} params = %{limit: 1000}
params = params =
if max_id == nil do if max_id == nil do

View file

@ -0,0 +1,10 @@
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

View file

@ -85,6 +85,25 @@ defmodule Pleroma.Elasticsearch do
) )
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 def search_activities(q) do
Elastix.Search.search( Elastix.Search.search(
url(), url(),

View file

@ -1,5 +1,9 @@
{ {
"properties": { "properties": {
"timestamp": {
"type": "date",
"index": true
},
"hashtag": { "hashtag": {
"type": "text" "type": "text"
} }