forked from YokaiRick/akkoma
Add logging to milisiearch index and make it use desc(id)
This commit is contained in:
parent
e961cf2689
commit
41db5c8653
1 changed files with 21 additions and 5 deletions
|
@ -3,8 +3,9 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
||||||
import Mix.Pleroma
|
require Logger
|
||||||
|
|
||||||
|
import Mix.Pleroma
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def run(["index"]) do
|
def run(["index"]) do
|
||||||
|
@ -12,12 +13,25 @@ def run(["index"]) do
|
||||||
|
|
||||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
||||||
|
|
||||||
|
{:ok, _} =
|
||||||
|
Pleroma.HTTP.post(
|
||||||
|
"#{endpoint}/indexes/objects/settings/ranking-rules",
|
||||||
|
Jason.encode!([
|
||||||
|
"desc(id)",
|
||||||
|
"typo",
|
||||||
|
"words",
|
||||||
|
"proximity",
|
||||||
|
"attribute",
|
||||||
|
"wordsPosition",
|
||||||
|
"exactness"
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
Pleroma.Repo.chunk_stream(
|
Pleroma.Repo.chunk_stream(
|
||||||
from(Pleroma.Object,
|
from(Pleroma.Object,
|
||||||
limit: 200,
|
|
||||||
where: fragment("data->>'type' = 'Note'") and fragment("LENGTH(data->>'source') > 0")
|
where: fragment("data->>'type' = 'Note'") and fragment("LENGTH(data->>'source') > 0")
|
||||||
),
|
),
|
||||||
100,
|
200,
|
||||||
:batches
|
:batches
|
||||||
)
|
)
|
||||||
|> Stream.map(fn objects ->
|
|> Stream.map(fn objects ->
|
||||||
|
@ -26,12 +40,14 @@ def run(["index"]) do
|
||||||
%{id: object.id, source: data["source"], ap: data["id"]}
|
%{id: object.id, source: data["source"], ap: data["id"]}
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|> Stream.each(fn activities ->
|
|> Stream.each(fn objects ->
|
||||||
{:ok, _} =
|
{:ok, _} =
|
||||||
Pleroma.HTTP.post(
|
Pleroma.HTTP.post(
|
||||||
"#{endpoint}/indexes/objects/documents",
|
"#{endpoint}/indexes/objects/documents",
|
||||||
Jason.encode!(activities)
|
Jason.encode!(objects)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
IO.puts("Indexed #{Enum.count(objects)} entries")
|
||||||
end)
|
end)
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue