add hashtag indexing

This commit is contained in:
FloatingGhost 2021-12-14 12:37:10 +00:00
parent 6bb19454fd
commit 8547cefaff
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.Pagination
alias Pleroma.User
alias Pleroma.Hashtag
@shortdoc "Manages elasticsearch"
@ -29,8 +30,16 @@ def run(["import", "users" | _rest]) do
|> 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

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 @@ def bulk_post(data, :users) do
)
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(),

View file

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